問題描述
我遇到了這個問題.我想這是某種 IE 錯誤,但我想確定一下.
所以問題是.為什么 IE10 XmlHttpRequest.status 返回 0 而不是 401?
var xmlhttp=new XMLHttpRequest();xmlhttp.onreadystatechange=函數(shù)(){如果(xmlhttp.readyState==4){document.getElementById("rescode").innerHTML="請求完成,狀態(tài)為:"+xmlhttp.status;}}xmlhttp.open("GET","http://hosting.gregy.cz/cors/",true);xmlhttp.send();
在這里查看插件:http://plnkr.co/edit/E2lCflPDHHaQi7t79IeM?p=previewp>
此代碼觸發(fā) CORS 請求,該請求始終返回 401.Firefox 和 chrome 在狀態(tài)屬性中正確返回 401,但 IE10 返回 0.此問題破壞了我用于項目的身份驗證處理方法.
謝謝
我已經(jīng)用 onload 和 onerror 事件處理程序修改了 plunker(來自 monsur 評論的提示),但結(jié)果仍然相同.
我還確定 IE10 沒有選擇兼容模式.(來自 cernunnos 評論的提示)
這似乎是 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 狀態(tài) 401 視為網(wǎng)絡(luò)錯誤.控制臺顯示:
SCRIPT7002:XMLHttpRequest:網(wǎng)絡(luò)錯誤 0x80070005,訪問被拒絕
根據(jù) XMLHttpRequest Level 2 規(guī)范,如果設(shè)置了錯誤標志(例如由于網(wǎng)絡(luò)錯誤),狀態(tài)屬性應(yīng)該為零.然而,該規(guī)范還聲明(http://www.w3.org/TR/XMLHttpRequest2/#infrastructure-for-the-send-method) 網(wǎng)絡(luò)錯誤
<塊引用>不包括指示某種類型錯誤的 HTTP 響應(yīng),例如作為 HTTP 狀態(tài)碼 410.
我認為很明顯 HTTP 狀態(tài) 401 不應(yīng)因此被視為網(wǎng)絡(luò)錯誤(因為它不在 Chrome、Firefox 和 Safari 中)并且這是 IE10 中的錯誤.
I have hit a wall with this issue. I guess it is some kind of IE bug but I want to be sure.
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();
See plunker here: http://plnkr.co/edit/E2lCflPDHHaQi7t79IeM?p=preview
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.
Thank you
Edit:
I have modified the plunker with onload and onerror event handlers (tip from monsur's comment), but the result is still the same.
I have also made sure IE10 has no compatibility mode selected. (tip from cernunnos's comment)
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 is treating HTTP status 401 as a network error. The console shows:
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied
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
does not include HTTP responses that indicate some type of error, such as HTTP status code 410.
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.
這篇關(guān)于XmlHttpRequest 狀態(tài) 0 而不是 IE 10 中的 401的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!