Umesh Patil
Umesh Patil

Reputation: 10685

xmlhttp request status 302

I am trying to write core java script application that can test and analyse the http request. I started with below code. Firebug net tab says 302 status error.

<script type="text/javascript">
$(document).ready(function(){
var req = new XMLHttpRequest();
req.open("GET","http://www.google.com",true);

req.onreadystatechange = statusListener;
req.send(null);
});
function statusListener(req){
    if (req.readyState == 4) 
        {
            if (req.status == 200) {
                var docx=req.responseXML;           
                console.log(docx);            
                }
        }
}
</script>

Upvotes: 0

Views: 4086

Answers (1)

Florian Margaine
Florian Margaine

Reputation: 60717

3xx status codes are redirections.

302 means "Found". Quote from w3.org:

The requested resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests.

If you want to get the page it redirects to, you have to check the URI in the response headers with the getResponseHeader() method.

You can see here to see how to access the correct URI.

Upvotes: 1

Related Questions