問題描述
我收到此錯誤
NETWORK_ERROR:XMLHttpRequest 異常 101
NETWORK_ERROR: XMLHttpRequest Exception 101
當試圖從一個站點獲取 XML 內容時.
when trying to get XML content from one site.
這是我的代碼:
var xmlhttp;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
if (xmlhttp==null) {
alert ("Your browser does not support XMLHTTP!");
return;
}
xmlhttp.onReadyStateChange=function() {
if(xmlhttp.readyState==4) {
var value =xmlhttp.responseXML;
alert(value);
}
}
xmlhttp.open("GET",url,false);
xmlhttp.send();
//alert(xmlhttp.responseXML);
}
xmlhttp.open("GET",url,false);
xmlhttp.send(null);
有人有解決辦法嗎?
推薦答案
如果您提供的url
位于您的服務器外部,并且服務器不允許您發送請求,則您有權限問題.您不能使用 XMLHttpRequest
從另一臺服務器訪問數據,除非服務器明確允許您這樣做.
If the url
you provide is located externally to your server, and the server has not allowed you to send requests, you have permission problems. You cannot access data from another server with a XMLHttpRequest
, without the server explicitly allowing you to do so.
更新: 意識到這現在可以在 Google 上看到作為答案,我試圖找到有關此錯誤的一些文檔.這太難了.
Update: Realizing this is now visible as an answer on Google, I tried to find some documentation on this error. That was surprisingly hard.
這篇文章,有一些背景信息和解決步驟.具體來說,它在這里提到了這個錯誤:
This article though, has some background info and steps to resolve. Specifically, it mentions this error here:
只要將服務器配置為允許來自您的 Web 應用程序的請求,XMLHttpRequest 就可以工作.否則會拋出 INVALID_ACCESS_ERR 異常
As long as the server is configured to allow requests from your web application's origin, XMLHttpRequest will work. Otherwise, an INVALID_ACCESS_ERR exception is thrown
INVALID_ACCESS_ERR 的解釋似乎是我們在這里看到的.
An interpretation of INVALID_ACCESS_ERR seems to be what we're looking at here.
要解決這個問題,必須將接收請求的服務器配置為允許來源.這在 Mozilla 的更多詳細信息中有描述.
To solve this, the server that receives the request, must be configured to allow the origin. This is described in more details at Mozilla.
這篇關于NETWORK_ERROR:XMLHttpRequest 異常 101的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!