Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
74 views
in Technique[技术] by (71.8m points)

javascript - 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)
     }
 });
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...