Side navigation
#9221 closed bug (fixed)
Opened May 10, 2011 09:28PM UTC
Closed May 11, 2011 12:14PM UTC
Last modified September 05, 2012 03:54PM UTC
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.
Attachments (0)
Change History (20)
Changed May 11, 2011 10:21AM UTC by comment:1
component: | unfiled → manipulation |
---|---|
keywords: | → script html |
owner: | → dmethvin |
priority: | undecided → high |
status: | new → assigned |
Changed May 11, 2011 12:07PM UTC by comment:3
milestone: | 1.next → 1.6.1 |
---|---|
owner: | dmethvin → jaubourg |
priority: | high → blocker |
Changed May 11, 2011 12:14PM UTC by comment:4
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
Changed December 05, 2011 06:14PM UTC by comment:5
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.
Changed December 27, 2011 08:55PM UTC by comment:6
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.
Changed April 27, 2012 01:33PM UTC by comment:8
I am getting this error, i tried using JQuery 1.7.2 ? Is there a fix for this?
Changed April 27, 2012 01:36PM UTC by comment:9
I am using IE9 and JQuert 1.7.2 and seeing this issue. Is there a fix?
Changed April 27, 2012 01:37PM UTC by comment:10
I am using IE9 and JQuery 1.7.2 and seeing this issue. Is there a fix for this?
Changed May 01, 2012 04:56AM UTC by comment:11
Replying to [comment:10 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.
Changed May 02, 2012 02:18AM UTC by comment:12
Please stop with the AOL-style "me toos" and provide a test case on a new ticket.
Changed May 02, 2012 02:55AM UTC by comment:13
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.
Changed June 04, 2012 09:38AM UTC by comment:14
Replying to [comment:13 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?
Changed July 16, 2012 07:51AM UTC by comment:15
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);
}
});
}
Changed July 31, 2012 02:16PM UTC by comment:16
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.
Changed July 31, 2012 03:02PM UTC by comment:17
Replying to [comment:16 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)
Changed August 22, 2012 02:38PM UTC by comment:18
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.
Changed August 22, 2012 03:08PM UTC by comment:19
It seems this is happening when some AJAX calls are made simultaneously.
Changed September 05, 2012 03:54PM UTC by comment:20
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?