访问被拒绝在IE 10和11当Ajax目标是本地主机 [英] Access denied in IE 10 and 11 when ajax target is localhost

查看:280
本文介绍了访问被拒绝在IE 10和11当Ajax目标是本地主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个服务器(HTTP),它是在互联网上的一个Ajax调用。和目标,为我自己的本地主机。 FF / Chrome浏览器/ E​​TC ...作品。它只是一个IE浏览器的问题。即时通讯使用IE 11和10。

I'm trying to do a ajax call between a server (http) that is on internet. And target that to my own localhost. FF/Chrome/ ETC... works. It's ONLY an IE issue. IM USING IE 11 AND 10.

该请求甚至不进行。而拒绝访问将立即抛出。

The request is don't even done. The "denied access" is thrown instantly.

这是在code。刚刚给你看。

This is the code. Just for you to see.

是不是在IE8和IE9经典的HTTP / HTTPS错误。这是另一回事,但文档是没有帮助的。

Is not the classical HTTP/HTTPS error in IE8 AND IE9. This is something else, but the documentation is not helpful.

$jq.ajax({
            contentType: 'application/json',
            url: url,
            dataType: 'json',
            crossDomain: true,
            beforeSend: function (xhr) {
                xhr.withCredentials = true; 
                xhr.setRequestHeader("Authorization", "Basic " + $jq.base64.encode(username and password));
            },
            success: function (data, status, headers) {},
            error: function (xhr, status, error) {}

状态为 0 XHR 对象,错误是拒绝访问

The status is 0 in xhr object and error is "Denied access"

推荐答案

Internet Explorer中引发此错误,因为它的安全区域功能的一部分。使用默认的安全设置,访问被拒绝的错误是试图从原点访问资源中的本地Intranet区域中的Internet区域时引发。

Internet Explorer raises this error as part of its security zones feature. Using default security settings, an "Access is Denied" error is raised when attempting to access a resource in the "Local intranet" zone from an origin in the "Internet" zone.

如果你是当您尝试打开资源编写的Ajax code手动,IE浏览器会产生一个错误。例如:

If you were writing your Ajax code manually, Internet Explorer would raise an error when you try to open the resource. For example:

var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://localhost/', true); // This line will trigger an error
xhr.send();

您可以通过添加源站点到受信任的站点安全区域解决此错误。您可以通过加入http://client.cors-api.appspot.com你的受信任的站点区域,并使用这个测试页面来测试这test-cors.org 与本地主机站点的远程URL。

You can work around this error by adding the origin site to the "Trusted sites" security zone. You can test this by adding "http://client.cors-api.appspot.com" to your "Trusted sites" zone and using this test page at test-cors.org with your localhost site as the Remote URL.

这篇关于访问被拒绝在IE 10和11当Ajax目标是本地主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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