拒绝访问 IE 上的 jQuery 脚本 [英] Access denied to jQuery script on IE

查看:24
本文介绍了拒绝访问 IE 上的 jQuery 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 jQuery 1.4.2 脚本的 iframe.相同的 iframe 被注入 httphttps 站点.jQuery 脚本作为相对路径包含在主 HTML 文件中(例如,/scripts/jquery-1.4.2.min.js).

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

进行 AJAX 调用时,Internet Explorer 拒绝访问.AJAX 正在调用另一个子域,但它使用了正确的协议.所有其他浏览器都可以工作,但 Internet Explorer 出现以下错误:

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:拒绝访问.
jquery-1.4.2.min.js,第 127 行字符 344

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

我听说这个错误来自跨域 AJAX 调用.但为什么 IE 是唯一一个给我废话的人?有IE解决方案吗?

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?

另外,这是我的 AJAX:

Also, this is my AJAX:

 $.ajax({
     url: thisURL,
     dataType: "json",
     data: {cmd : 'getMessage', uurl: urlVar, t: Math.random()},
     success: function(ret){
         callback(ret)
     }
 });

推荐答案

IE 要求你使用 XDomainRequest 而不是 XHR 跨站点,你可以尝试类似...

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)
                    }
            });

        }

参考

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

不确定它是否适合您的场景

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]); 

您可以在此处

这篇关于拒绝访问 IE 上的 jQuery 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆