admin管理员组文章数量:1410674
I upgraded from jQuery 1.4.2 to 1.6.2 and now I get error(in IE). I have JavaScript on the page that gets executed by jQuery globalEval()
function
// Evaluates a script in a global context
// Workarounds based on findings by Jim Driscoll
//
globalEval: function( data ) {
if ( data && rnotwhite.test( data ) ) {
// We use execScript on Internet Explorer
// We use an anonymous function so that context is window
// rather than jQuery in Firefox
( window.execScript || function( data ) {
window[ "eval" ].call( window, data );
} )( data );
}
},
In IE the call throws exception:
"Error: Could not plete the operation due to error 80020101."
The data parameter that get executed is javascript variables on page surrounded by <!-- -->
<!--
var id = \"ctrl90900\";
var url = \"myur/blah.html\";
-->
I'm using IE9, and jQuery 1.6.2 Not sure why this would cause an error.
I upgraded from jQuery 1.4.2 to 1.6.2 and now I get error(in IE). I have JavaScript on the page that gets executed by jQuery globalEval()
function
// Evaluates a script in a global context
// Workarounds based on findings by Jim Driscoll
// http://weblogs.java/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
globalEval: function( data ) {
if ( data && rnotwhite.test( data ) ) {
// We use execScript on Internet Explorer
// We use an anonymous function so that context is window
// rather than jQuery in Firefox
( window.execScript || function( data ) {
window[ "eval" ].call( window, data );
} )( data );
}
},
In IE the call throws exception:
"Error: Could not plete the operation due to error 80020101."
The data parameter that get executed is javascript variables on page surrounded by <!-- -->
<!--
var id = \"ctrl90900\";
var url = \"myur./blah.html\";
-->
I'm using IE9, and jQuery 1.6.2 Not sure why this would cause an error.
Share edited Aug 16, 2011 at 3:41 alex 491k204 gold badges889 silver badges991 bronze badges asked Aug 15, 2011 at 23:43 dev.e.loperdev.e.loper 36.1k77 gold badges167 silver badges257 bronze badges 3- 1 Does it work if you remove the menting? It is not valid JavaScript. – alex Commented Aug 15, 2011 at 23:47
-
Try using this regex on the string before passing to
$.globalEval()
->str = str.replace(/<!--\s*([\s\S]*?)\s*-->/, '$1');
jsFiddle. – alex Commented Aug 15, 2011 at 23:56 - I may as well post it as an answer then :) – alex Commented Aug 16, 2011 at 1:43
3 Answers
Reset to default 2If there is any error at all in a script passed to execScript, as far is Internet Explorer is concerned, it will report a 80020101 instead of the original error.
So, also check for missing semicolons and JS features not supported by IE.
For short code passages, i found the most effective debugging technique was to ment out parts of code and see if the error still turns up. If it doesn't, examine the code block that was just mented out for above errors.
It might be the menting of the code, which is invalid JavaScript and unnecessary in this day and age.
You can strip it out with this regex...
$.globalEval(str.replace(/<!--\s*([\s\S]*?)\s*-->/, '$1'));
jsFiddle.
Just wanted to add a bit to this -- I was getting an error 80020101 whenever in an AJAX-called PHP script that included JavaScript. The script inside the PHP file was also breaking somehow, and refusing to render any of the script in the designated div (other elements of the PHP came through, but nothing inside the JavaScript -- I was trying to draw a chart using HighChart).
Turns out there was an undefined PHP function inside the JavaScript in the included PHP file (used to echo some text). I found this using Firebug.
So bottom line, make sure you don't have any undefined functions inside code ing back via AJAX.
本文标签:
版权声明:本文标题:After upgrading to jQuery 1.6.2, globalEval throws an error when trying to execute javascript on page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744948975a2633962.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论