#9221 closed bug (fixed)
Javascript within AJAX fails to load in IE - Error 80020101
Reported by: | jeff.rigby | Owned by: | jaubourg |
---|---|---|---|
Priority: | blocker | Milestone: | 1.6.1 |
Component: | manipulation | Version: | 1.6 |
Keywords: | script html | Cc: | |
Blocked by: | Blocking: |
Description
IE can't load/trigger scripts returned with AJAX in JQuery 1.6 if the script is wrapped in a cdata comment (the default way Drupal outputs javascript).
IE returns the following error:
SCRIPT1002: Syntax error test.html, line 2 character 1 SCRIPT257: Could not complete the operation due to error 80020101. jquery.min.js, line 16 character 11792
You can reproduce this with the following code:
test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title></title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script> </head> <body> <div id="ajax">Loading AJAX</div> <script type="text/javascript"> $.ajax({ url: "ajax.html", success: function(html){ $("#ajax").html(html); } }); </script> </body> </html>
ajax.html
<script type="text/javascript"> <!--//--><![CDATA[//><!-- alert('Show Alert'); //--><!]]> </script>
This does work without the cdata comment wrapping and in all other major browsers. This was not a problem with 1.5.2.
Change History (20)
comment:1 Changed 12 years ago by
Component: | unfiled → manipulation |
---|---|
Keywords: | script html added |
Owner: | set to dmethvin |
Priority: | undecided → high |
Status: | new → assigned |
comment:3 Changed 12 years ago by
Milestone: | 1.next → 1.6.1 |
---|---|
Owner: | changed from dmethvin to jaubourg |
Priority: | high → blocker |
comment:4 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixes #9221. Wraps openings of html comments and CDATA blocks found at the beginning of inserted script elements into a javascript block comment so that the new implementation of globalEval will not throw an exception in IE (execScript being less lenient than eval). Unit tests added.
Changeset: 391398cf23603201f63c6e815a287e0cb107988c
comment:5 Changed 12 years ago by
Semi-related, but I am getting this exact same error with a plain straight-forward jQuery().load() request.
As part of trying to track down the problem, I coded the request in native javascript and found that I was getting an "Access Denied" error on the native XMLHttpRequest.
Not sure if I'm providing the proper details, but feel free to contact me if you want more info.
comment:6 Changed 12 years ago by
i never had this issue with jquery 1.6x. when i upgraded recently to 1.7.1, this started happening all the time. i do not have any comments in my scripts, but i do have doctype tags. would this effect anything? i had to rollback to v 1.6.1 but would like to go back to 1.7.1+ if possible.
comment:8 Changed 11 years ago by
I am getting this error, i tried using JQuery 1.7.2 ? Is there a fix for this?
comment:9 Changed 11 years ago by
I am using IE9 and JQuert 1.7.2 and seeing this issue. Is there a fix?
comment:10 follow-up: 11 Changed 11 years ago by
I am using IE9 and JQuery 1.7.2 and seeing this issue. Is there a fix for this?
comment:11 Changed 11 years ago by
Replying to anonymous:
I am using IE9 and JQuery 1.7.2 and seeing this issue. Is there a fix for this?
I'm having the same issue. I had to roll all the way back to 1.4.4 to get it to work correctly.
comment:12 Changed 11 years ago by
Please stop with the AOL-style "me toos" and provide a test case on a new ticket.
comment:13 follow-up: 14 Changed 11 years ago by
The issues are caused by http://bugs.jquery.com/ticket/11402 There is a valid fiddle there. I had accidentally marked it as a dupe and then reopened a few months ago.
comment:14 Changed 11 years ago by
Replying to mikesherov:
The issues are caused by http://bugs.jquery.com/ticket/11402 There is a valid fiddle there. I had accidentally marked it as a dupe and then reopened a few months ago.
I am using Firefox 12 and JQuery 1.7.2 and getting syntax error for <!DOCTYPE HTML>. Has this issue been fixed in the latest?
comment:15 Changed 11 years ago by
IE error 80020101.
No One Giving Perfect Solutions....
We Have Two Pages in ASPX. One page for display HTML(get data from Other Page) from Another URL. The Other page is display Flash file.All Brwoser is working fine . But not working on IE Brwoser.IE is giving Error 80020101.
Please resolve it. My Functions is Writedown below
function Two()
{
$.ajax({ url:"GetBookingQueue.aspx?ID=5", success: function(data){
$("#getBookingQueue").html(data);
}
});
}
comment:16 follow-up: 17 Changed 11 years ago by
In our case the problem was due to a problem of character encoding
It occurs when using an ajax function in jquery and the document loaded by the function is saved in ANSI (iso-8859-1) When you want to evaluate the jquery character breaks the execution.
Solution: We changed to UTF-8 format of the document is loaded via ajax.
En nuestro caso el problema se debio a un problema del encoding character
Ocurre cuando se usa una funcion de ajax en jquery y el documento cargado por esa funcion esta guardado en ANSI (iso-8859-1) Cuando jquery lo quiere evaluar el caracter rompe la ejecucion.
Solucion: Cambiamos a UTF-8 el formato del documento que es cargado via ajax.
comment:17 Changed 11 years ago by
Replying to laconeo@…:
In our case the problem was due to a problem of character encoding
It occurs when using an ajax function in jquery and the document loaded by the function is saved in ANSI (iso-8859-1) When you want to evaluate the jquery character breaks the execution.
Solution: We changed to UTF-8 format of the document is loaded via ajax.
En nuestro caso el problema se debio a un problema del encoding character
Ocurre cuando se usa una funcion de ajax en jquery y el documento cargado por esa funcion esta guardado en ANSI (iso-8859-1) Cuando jquery lo quiere evaluar el caracter rompe la ejecucion.
Solucion: Cambiamos a UTF-8 el formato del documento que es cargado via ajax.
Affect when accented characters or is malformed code javascript ajax loaded in the file.
Afecta cuando hay caracteres con acentos o esta mal formado el codigo javascript cargado en el archivo ajax.
b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)
comment:18 Changed 11 years ago by
Hey guys, I have page, where I'm making an ajax call to PageMethod, and as a result I'm getting some html string, which I need to append to some div. Now Html string has some javascript code in it, so I expect this js code to execute, after I append html to div. But the problem is, I'm getting error saying that - "Microsoft JScript runtime error: Access is denied.", this error gets thrown when globalEval method tries to execute.
This a ajax call I make
var data ={id: id}; $.ajax({ type: "POST", url: "/srv/Loader.aspx/LoadUserControl", contentType: "application/json; charset=utf-8", data: JSON.stringify(data), dataType: "json", //tried with "text/html" as well. success: function (data) { $('#TargetDivID').html(data.d); }, error: function (error) { $('#TargetDivID').html("Control can not be loaded"); console.log("LOG: Exeption trying to load Control:\n" + error.responseText); } });
Here is the Html returned by WebMethod:
<div class="someclass" id="inHouseAdModule" style="display:none;"> Some Html Content <script type="text/javascript"> Some logic goes here </script> </div>
I'm getting back expected results in success function of my ajax call, I just can't execute js code.
comment:19 Changed 11 years ago by
It seems this is happening when some AJAX calls are made simultaneously.
comment:20 Changed 11 years ago by
Saw this same problem come up with IE9 compatibility mode turned on. Goes away once viewing mode is switched to regular.
There is a problem in the way you escape script code when in XHTML code. I can confirm your technique breaks in IE9 and IE8 (probably earlier too).
Here is what I came up with: http://jsfiddle.net/pgxVx/
Note that it has nothing to do with $.ajax() but seems to be related to $.html(). The more cautious escaping technique seems to work perfectly and is an immediate fix for you ;)
However, I have no clue why this is breaking in 1.6 while it worked in 1.5.2: I'll defer to DaveMethvin, with this interrogation: afaik, <!-- --> is perfectly valid in XHTML, isn't it? Why would it become part of the script code when IE executes it?