NETWORK_ERR: XMLHttpRequest Exception 101

匿名 (未验证) 提交于 2019-12-03 01:33:01

问题:

I'm having an AJAX problem in Chrome, giving the following error:

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; } 

回答1:

The solution is setting the async parameter to true:

xmlhttp.open("GET", filename+"?random="+Math.floor(Math.random()*100000001), true); 


回答2:

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).

Still happening as of Chrome version 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.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!