拒绝访问jQuery脚本在IE浏览器 [英] Access denied to jQuery script on IE

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

问题描述

我使用jQuery 1.4.2脚本的iframe。同样的IFRAME注入到这两个 HTTP HTTPS 网​​站。 jQuery的脚本是包含在主HTML文件为相对路径(例如,/scripts/jquery-1.4.2.min.js)。

当一个AJAX调用时,IE浏览器拒绝访问。阿贾克斯呼吁另一个子域,但它的使用权协议。所有其他浏览器,但Internet Explorer中提供了以下错误:

  

SCRIPT5:访问被拒绝
。   jQuery的-1.4.2.min.js,线路127字符344

我听说这个错误的跨域Ajax调用。但是,为什么是IE是唯一一个给我废话?是否有一个IE浏览器的解决方案?

此外,这是我的AJAX:

  $。阿贾克斯({
     网址:thisURL,
     数据类型:JSON,
     数据:{CMD:的getMessage,uurl:urlVar,T:的Math.random()},
     成功:函数(RET){
         回调(RET)
     }
 });
 

解决方案

IE浏览器需要您使用,而不是XHR XDomainRequest跨站点,您可以尝试这样...

 如果($ .browser.msie&功放;&安培; window.XDomainRequest){
            //使用Microsoft XDR
            VAR XDR =新XDomainRequest();
            xdr.open(获取,网址);
            xdr.onload =功能(){
                // XDomainRequest不提供responseXML的,所以如果你需要它:
                VAR DOM =新的ActiveXObject(Microsoft.XMLDOM);
                dom.async = FALSE;
                dom.loadXML(xdr.responseText);
            };
            xdr.send();
        } 其他 {
            //你的阿贾克斯在这里要求
            $$。阿贾克斯({
                   网址:thisURL,
                   数据类型:JSON,
                   数据:{CMD:的getMessage,uurl:urlVar,T:的Math.random()},
                   成功:函数(RET){
                               回调(RET)
                    }
            });

        }
 

参考

<一个href="http://forum.jquery.com/topic/cross-domain-ajax-and-ie">http://forum.jquery.com/topic/cross-domain-ajax-and-ie

不知道它是否适合你的方案

  XDR =新XDomainRequest();
xdr.onload =功能()
{
    警报(xdr.responseText);
}
xdr.open(GET,thisUrl); // thisURl  - &GT;您的跨域请求的URL
//这里通过你的数据
xdr.send([资料]);
 

您可以在这里多找一些指导

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

解决方案

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

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

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