Javascript NETWORK_ERR:XMLHttpRequest 异常 101
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6965942/
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
NETWORK_ERR: XMLHttpRequest Exception 101
提问by Pawan Goswami
I'm having an AJAX problem in Chrome, giving the following error:
我在 Chrome 中遇到 AJAX 问题,出现以下错误:
Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101
This is my code:
这是我的代码:
function IO(filename) {
if (window.XMLHttpRequest) { // Mozilla, Safari,...
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) { }
}
}
xmlhttp.open("GET", filename+"?random="+Math.floor(Math.random()*100000001), false);
xmlhttp.send();
if(xmlhttp.readyState==4)
return xmlhttp.responseXML;
}
回答by headmax
The solution is setting the async
parameter to true
:
解决方案是将async
参数设置为true
:
xmlhttp.open("GET", filename+"?random="+Math.floor(Math.random()*100000001), true);
回答by AlexChaffee
In addition to happening when fetching a cross-site URL without proper headers, this error occurs when fetching a local file via XHR (AJAX). Apparently Chrome is being overzealous with its cross-site security measures, not realizing that one file: URL should be considered the same site as another file: URL. This is a problem for many homegrown apps, especially Jasmine (a JavaScript testing framework).
除了在没有正确标头的情况下获取跨站点 URL 时发生之外,在通过 XHR (AJAX) 获取本地文件时也会发生此错误。显然,Chrome 对其跨站点安全措施过于热情,没有意识到应该将一个 file: URL 视为与另一个 file: URL 相同的站点。这是许多本土应用的问题,尤其是 Jasmine(一个 JavaScript 测试框架)。
Still happening as of Chrome version 16.0.912.63 .
从 Chrome 版本 16.0.912.63 开始仍在发生。
I don't know any solution. Workaround is to use Firefox, or any other browser, to run apps served off of file: URLs.
我不知道有什么解决办法。解决方法是使用 Firefox 或任何其他浏览器来运行由 file: URL 提供的应用程序。