Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access denied to jQuery script on IE

I have an iframe using the jQuery 1.4.2 script. The same iframe is injected into both http and https sites. The jQuery script is included in the main HTML file as a relative path (e.g., /scripts/jquery-1.4.2.min.js).

When an AJAX call is made, Internet Explorer denies access. The AJAX is calling on another subdomain, but it's using the right protocol. All other browsers work but Internet Explorer gives the following error:

SCRIPT5: Access is denied.
jquery-1.4.2.min.js, line 127 character 344

I heard this error is from cross-domain AJAX calls. But why is IE the only one giving me crap? Is there an IE solution?

Also, this is my AJAX:

 $.ajax({      url: thisURL,      dataType: "json",      data: {cmd : 'getMessage', uurl: urlVar, t: Math.random()},      success: function(ret){          callback(ret)      }  }); 
like image 962
Kyle Cureau Avatar asked Feb 23 '11 06:02

Kyle Cureau


1 Answers

IE requires you to use XDomainRequest instead of XHR for cross site, you can try something like...

if ($.browser.msie && window.XDomainRequest) {             // Use Microsoft XDR             var xdr = new XDomainRequest();             xdr.open("get", url);             xdr.onload = function() {                 // XDomainRequest doesn't provide responseXml, so if you need it:                 var dom = new ActiveXObject("Microsoft.XMLDOM");                 dom.async = false;                 dom.loadXML(xdr.responseText);             };             xdr.send();         } else {             // your ajax request here             $$.ajax({                    url: thisURL,                    dataType: "json",                    data: {cmd : 'getMessage', uurl: urlVar, t: Math.random()},                    success: function(ret){                                callback(ret)                     }             });          } 

Reference

http://forum.jquery.com/topic/cross-domain-ajax-and-ie

not sure whether it fits your scenario

xdr = new XDomainRequest();  xdr.onload=function() {     alert(xdr.responseText); } xdr.open("GET", thisUrl); //thisURl ->your cross domain request URL  //pass your data here xdr.send([data]);  

you can find some more guidance here

like image 168
Rafay Avatar answered Oct 03 '22 19:10

Rafay