9

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
  • What is filename you're using?
    – pimvdb
    Commented Aug 6, 2011 at 9:41

2 Answers 2

12

The solution is setting the async parameter to true:

xmlhttp.open("GET", filename+"?random="+Math.floor(Math.random()*100000001), true);
0
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.

1
  • 5
    You can start chrome with the --allow-file-access-from-files switch. Commented Mar 10, 2012 at 23:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.