問題描述
我收到此錯(cuò)誤
NETWORK_ERROR:XMLHttpRequest 異常 101
NETWORK_ERROR: XMLHttpRequest Exception 101
當(dāng)試圖從一個(gè)站點(diǎn)獲取 XML 內(nèi)容時(shí).
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
位于您的服務(wù)器外部,并且服務(wù)器不允許您發(fā)送請(qǐng)求,則您有權(quán)限問題.您不能使用 XMLHttpRequest
從另一臺(tái)服務(wù)器訪問數(shù)據(jù),除非服務(wù)器明確允許您這樣做.
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.
更新: 意識(shí)到這現(xiàn)在可以在 Google 上看到作為答案,我試圖找到有關(guān)此錯(cuò)誤的一些文檔.這太難了.
Update: Realizing this is now visible as an answer on Google, I tried to find some documentation on this error. That was surprisingly hard.
這篇文章,有一些背景信息和解決步驟.具體來說,它在這里提到了這個(gè)錯(cuò)誤:
This article though, has some background info and steps to resolve. Specifically, it mentions this error here:
只要將服務(wù)器配置為允許來自您的 Web 應(yīng)用程序的請(qǐng)求,XMLHttpRequest 就可以工作.否則會(huì)拋出 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 的解釋似乎是我們?cè)谶@里看到的.
An interpretation of INVALID_ACCESS_ERR seems to be what we're looking at here.
要解決這個(gè)問題,必須將接收請(qǐng)求的服務(wù)器配置為允許來源.這在 Mozilla 的更多詳細(xì)信息中有描述.
To solve this, the server that receives the request, must be configured to allow the origin. This is described in more details at Mozilla.
這篇關(guān)于NETWORK_ERROR:XMLHttpRequest 異常 101的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!