Javascript XMLHttpRequest:网络错误 0x80070005,Microsoft Edge 上的访问被拒绝(但不是 IE)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30896958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XMLHttpRequest: Network Error 0x80070005, Access is denied on Microsoft Edge (but not IE)
提问by HockeyJ
I have a very simple ajax request (see below). The server is using CORS and works fine in IE 10+, Chrome, Firefox and Opera. On Microsoft Edgehowever, it fails with
我有一个非常简单的 ajax 请求(见下文)。服务器正在使用 CORS 并且在 IE 10+、Chrome、Firefox 和 Opera 中运行良好。然而,在Microsoft Edge 上,它失败了
XMLHttpRequest: Network Error 0x80070005, Access is denied.
XMLHttpRequest:网络错误 0x80070005,拒绝访问。
I have researched the posts here, here, hereand here, but cannot find an answer that works. Those people have had issues with IE, but adding the contentType (not required for this get) and crossDomain has it working fine.
我已经研究过这里、这里、这里和这里的帖子,但找不到有效的答案。那些人在使用 IE 时遇到了问题,但是添加了 contentType(此 get 不需要)和 crossDomain 使其工作正常。
CanIUseseems to state that CORS is usable in Edge. The request also fails on IE9 down, but CanIUse states only partial support for CORS, so that's understandable.
CanIUse似乎声明 CORS 在 Edge 中可用。该请求在 IE9 上也失败,但 CanIUse 声明仅部分支持 CORS,所以这是可以理解的。
Any ideas how I can fix this please?
有什么想法可以解决这个问题吗?
Code:
代码:
$.ajax({
crossDomain: true,
url: "http://localhost:2023/api/DoAction/test",
success: function (a) {
var res = JSON.parse(a);
alert(res.content);
},
error: function (a, e, r) {
alert(a.responseText);
}
});
Update
更新
To add further information in case it provides any clues - the ajax request is coming from Azure and posting to a localhost website created using OWIN self hosting. This is unusual, but required for the software (which can only be used locally) to get data from a cloud service. As stated, it works fine for all other browsers, Edge is the only problem.
添加更多信息以防它提供任何线索 - ajax 请求来自 Azure 并发布到使用 OWIN 自托管创建的本地主机网站。这是不寻常的,但需要软件(只能在本地使用)从云服务获取数据。如前所述,它适用于所有其他浏览器,Edge 是唯一的问题。
采纳答案by Sampson
This problem should no longer exist for developers using Microsoft Edge. If you experience issues with localhost testing, navigate to about:flags, and make sure Allow localhost loopbackis checked.
使用 Microsoft Edge 的开发人员应该不再存在此问题。如果您在 localhost 测试中遇到问题,请导航到about:flags,并确保选中Allow localhost loopback。
Microsoft Edge does not currentlysupport (out of the box) localhost testing. You can however enable it by following the guidance provided here: http://dev.modern.ie/platform/faq/how-can-i-debug-localhost/.
Microsoft Edge当前不支持(开箱即用)本地主机测试。但是,您可以按照此处提供的指南启用它:http: //dev.modern.ie/platform/faq/how-can-i-debug-localhost/。
We're working on resolving this in a future release.
我们正在努力在未来的版本中解决这个问题。
回答by David Wengier
For Build 10158 the command has changed slightly, with the rebranding of Spartan fully into Microsoft Edge, so to enable it in Microsoft Edge run the following command from an administrator command prompt:
对于 Build 10158,命令略有变化,将 Spartan 完全重新命名为 Microsoft Edge,因此要在 Microsoft Edge 中启用它,请从管理员命令提示符运行以下命令:
CheckNetIsolation.exe LoopbackExempt -a -n=Microsoft.MicrosoftEdge_8wekyb3d8bbwe
回答by Cedric Michel
Just before your ajax call use this : $.support.cors = true;
就在你的 ajax 调用之前使用这个: $.support.cors = true;