Ajax.Request: scripts not eval in the global scope
Reported by tsveg1 | May 15th, 2008 @ 10:31 AM | in 1.6.1
The problem is in an Ajax.Request Call.
In the evalScript Function javascripts are evaluated locally and not on the page (DOM). If I've got same new script in Response they are not correctly evaluated.
evalScripts: function() {
return this.extractScripts().map(function(script) { return eval(script) });
Suppose I define a new variable script (var dummy = 10). This code doesn't work because the script is not evaluated on the dom (an example is popup component in tomahawk jsf component).
The possible correction is:
evalScripts: function() {
return this.extractScripts().map(
function(script)
{
try {
if (window.execScript) { // Eval correctly in IE return window.execScript(script);
} else { // Eval correctly in FF
return window.eval(script);
}
} catch (e)
{}
}
);
Comments and changes to this ticket
-
John-David Dalton August 8th, 2008 @ 04:53 PM
- → Tag cleared.
- → Milestone changed from to 1.6.1
- → State changed from new to enhancement
- → Assigned user changed from Andrew Dupont to John-David Dalton
This and other issues would be fixed by implimenting a globalEval solution similar to jQuery's.
-
Juriy Zaytsev August 8th, 2008 @ 06:43 PM
Meanwhile, one could reference global properties explicitly (in a script block which is to be evaluated):
window.foo = 'bar'; // or a safer approach: (function(){ this.foo = 'bar'; })();
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
The Prototype JavaScript library.
