Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
626 views
in Technique[技术] by (71.8m points)

ajax - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...