On Mar 21, 2012, at 12:11 PM, Aravinda777 wrote:

> Hi all,
> 
> I used Prototype to get an AJAX response fromcalling a JSP page, and
> set it as innerHTML of a div.
> 
> I tried executing eval on the response separately before going with
> Prototype, and seeing that prototype evaluates javascript in the
> reponseText, I gave it a spin. However, when I try using the
> javascript functionality after setting the innerHTML, still it does
> not seem to have got evaluated.
> 
> My sample JSP code looks like this:
> 
> 
> <script type="text/javascript">
> function sayHi(){
>       alert("hi");
> }
> </script>
> <p>test</p>
> <input type="button" value="click" onClick="sayHi()">
> 
> I do the AJAX call like this on another page of the same app:
> 
> new Ajax.Request(page, {
>                 onSuccess: function(reponse) {
>       
> document.getElementById('test_div').innerHTML=reponse.responseText;
>                 }
>               });
> 
> When I click the button, I do not get the alert - which I can get if I
> accessed the JSP dierctly. Is there something additional I need to do
> to get the sayHi() function working in the target div? Or probably I
> am missing something trivial altogether.

Try this:

new Ajax.Updater('test_div', page, { evalScripts: true  }});

I see two things wrong with what's going on in yours. First, you're duplicating 
existing functionality, second, you're using document.getElementById() instead 
of $(). While these two are basically identical in that they perform an 
id-based object lookup, the Prototype dollar function also extends the found 
object with all of the Prototype functionality in browsers that do not support 
prototypical "inheritance". If you really wanted to have your own version of 
Ajax.Updater using Ajax.Request (for some other custom purpose not shown here) 
then you might write your code like this:

new Ajax.Request(page, {
        onSuccess: function(reponse) {
                $('test_div').update(reponse.responseText);
        }
});

Walter

> 
> Appreciate your help on this.
> 
> Regards,
> -A
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Prototype & script.aculo.us" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/prototype-scriptaculous?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to