XmlHttpRequest status 0而不是IE 10中的401 [英] XmlHttpRequest status 0 instead of 401 in IE 10
问题描述
我遇到了这个问题。我想这是某种IE错误,但我想确定。
I have hit a wall with this issue. I guess it is some kind of IE bug but I want to be sure.
所以问题是。为什么IE10 XmlHttpRequest.status返回0而不是401?
So the question is. Why does IE10 XmlHttpRequest.status returns 0 instead of 401?
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
{
document.getElementById("rescode").innerHTML="Request completed with status: "+xmlhttp.status;
}
}
xmlhttp.open("GET","http://hosting.gregy.cz/cors/",true);
xmlhttp.send();
请参阅plunker here: http://plnkr.co/edit/E2lCflPDHHaQi7t79IeM?p=preview
See plunker here: http://plnkr.co/edit/E2lCflPDHHaQi7t79IeM?p=preview
此代码触发一个始终返回401的CORS请求。 Firefox和chrome正确地返回401状态属性,但IE10返回0.这个问题打破了我用于我的项目的身份验证处理方法。
This code fires a CORS request which always returns 401. Firefox and chrome correctly return 401 in status attribute but IE10 returns 0. This issue breaks authentication handling methods I use for my project.
谢谢
编辑:
我已使用onload和onerror事件处理程序修改plunker(tip from monsur的注释)但结果仍然是一样的。
I have modified the plunker with onload and onerror event handlers (tip from monsur's comment), but the result is still the same.
我也确保IE10没有选择兼容模式。 (来自cernunnos的评论)
I have also made sure IE10 has no compatibility mode selected. (tip from cernunnos's comment)
推荐答案
这似乎是IE10的一个错误( https: //connect.microsoft.com/IE/feedback/details/785990/ie-10-on-win8-does-not-assign-the-correct-status-to-xmlhttprequest-when-the-result-is-401 )。
This appears to be a bug in IE10 (https://connect.microsoft.com/IE/feedback/details/785990/ie-10-on-win8-does-not-assign-the-correct-status-to-xmlhttprequest-when-the-result-is-401).
IE10将HTTP状态401视为网络错误。控制台显示:
IE10 is treating HTTP status 401 as a network error. The console shows:
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied
根据XMLHttpRequest Level 2规范,如果设置了错误标志(例如由于网络错误),状态属性应为零。但是,规范还规定( http://www.w3.org/TR/XMLHttpRequest2 /#infrastructure-for-the-send-method )网络错误
According to the XMLHttpRequest Level 2 specification the status attribute should be zero if the error flag is set (for example because of a network error). However the specification also states (http://www.w3.org/TR/XMLHttpRequest2/#infrastructure-for-the-send-method) that a network error
不包括HTTP响应,类型的错误,如
作为HTTP状态代码410.
does not include HTTP responses that indicate some type of error, such as HTTP status code 410.
我认为很明显,HTTP状态401不应该被视为网络错误(因为它不是在Chrome,Firefox和Safari),这是在IE10中的错误。
I think it is clear that HTTP status 401 should not therefore be treated as a network error (as it is not in Chrome, Firefox and Safari) and that this is a bug in IE10.
这篇关于XmlHttpRequest status 0而不是IE 10中的401的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!