最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - NETWORK_ERR: XMLHttpRequest Exception 101 - Stack Overflow

programmeradmin5浏览0评论

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

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;
}
Share Improve this question edited Aug 6, 2011 at 21:41 pimvdb 155k80 gold badges311 silver badges356 bronze badges asked Aug 6, 2011 at 9:34 Pawan GoswamiPawan Goswami 911 gold badge1 silver badge2 bronze badges 1
  • What is filename you're using? – pimvdb Commented Aug 6, 2011 at 9:41
Add a comment  | 

2 Answers 2

Reset to default 12

The solution is setting the async parameter to true:

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

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.

发布评论

评论列表(0)

  1. 暂无评论