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
Add a ment  | 

3 Answers 3

Reset to default 2

If 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.

本文标签: