当 ajax 目标是 localhost 时,IE 10 和 11 中的访问被拒绝 [英] Access denied in IE 10 and 11 when ajax target is localhost

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

问题描述

我正在尝试在 Internet 上的服务器 (http) 之间进行 ajax 调用.并将其定位到我自己的本地主机.FF/Chrome/ETC ... 有效.这只是一个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.

这是代码.只给你看.

这不是 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) {}

xhr 对象中的状态为 0 并且错误为拒绝访问"

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

推荐答案

Internet Explorer 作为其安全区域功能的一部分引发此错误.使用默认安全设置,尝试从Internet"区域中的源访问本地 Intranet"区域中的资源时,会引发访问被拒绝"错误.

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 代码,Internet Explorer 会在您尝试打开资源时引发错误.例如:

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.

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

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