This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am having some issues getting the response Text of an AJAX request to evaluate the scripts within the HTML response. I am using the Prototype function 'evalScripts()' but it doesn't want to work correctly for some reason. Please see the simple example below 'Main.jsp' which dynamically loads another file 'ajaxtest.jsp' into the innerHTML of a DHTML div tag.
The above gives the error back 'myVariable' is undefined (when clicking the 'TEST' button)
If you use evalScripts: true, any <script> block will be evaluated. This does not mean it will get included in the page: they won't. Their content will simply be passed to the native eval() function. There are two consequences to this:
The local scope will be that of Prototype's internal processing function. Anything in your script declared with var will be discarded momentarily after evaluation, and at any rate will be invisible to the remainder of the page scripts.
If you define functions in there, you need to actually create them, otherwise they won't be accessible to the remainder of the page scripts. ...
Which means when I declared the variable 'myVariable' it was not in the global scope and thus could not be evaluated by the function 'alertVariable' when the 'TEST' button is clicked.
Does anyone know a way around this?? [ May 01, 2007: Message edited by: Scott McGhee ]