Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NETWORK_ERROR: XMLHttpRequest Exception 101

I am getting this Error

NETWORK_ERROR: XMLHttpRequest Exception 101

when trying to get XML content from one site.

Here is my code:

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

Does any one have a solution?

like image 980
pawan Mangal Avatar asked Feb 10 '10 10:02

pawan Mangal


4 Answers

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.

Update: Realizing this is now visible as an answer on Google, I tried to find some documentation on this error. That was surprisingly hard.

This article though, has some background info and steps to resolve. Specifically, it mentions this error here:

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

An interpretation of INVALID_ACCESS_ERR seems to be what we're looking at here.

To solve this, the server that receives the request, must be configured to allow the origin. This is described in more details at Mozilla.

like image 143
Frederik Wordenskjold Avatar answered Nov 07 '22 04:11

Frederik Wordenskjold


The restriction that you cannot access data from another server with a XMLHttpRequest can apply even if the url just implies a remote server.

So: url = "http://www.myserver.com/webpage.html"

may fail,

but: url = "/webpage.html"

succeed - even if the request is being made from www.myserver.com

like image 4
Ian Avatar answered Nov 07 '22 06:11

Ian


Request aborted because it was cached or previously requested? It seems the XMLHttpRequest Exception 101 error can be thrown for several reasons. I've found that it occurs when I send an XMLHttpRequest with the same URL more than one time. (Changing the URL by appending a cache defeating nonsense string to the end of the URL allows the request to be repeated. -- I wasn't intending to repeat the request, but events in the program caused it to happen and resulted in this exception).

Not returning the correct responseText or responseXML in the event of a repeated request is a bug (probably webKit).

When this exception occurred, I did get an onload event with readyState==4 and the request object state=0 and responseText=="" and responseXML==null. This was a cross domain request, which the server permits.

This was on an Android 2.3.5 system which uses webKit/533.1

Anyone have documentation on what the exception is supposed to mean?

like image 3
Ribo Avatar answered Nov 07 '22 06:11

Ribo


Something like this happened with me when I returned incorrect XML (I put an attribute in the root node). In case this helps anyone.

like image 2
Mart van de Sanden Avatar answered Nov 07 '22 06:11

Mart van de Sanden