views:

219

answers:

1

I am requesting something with $.ajax and i am getting a 302 or 200 status after the call. I want to insert something into the DOM when status is 200 and make the actual redirect when the status returned is 302.

For that I am using: (took that snippet from a diffrent thread here)

complete: function (XMLHttpRequest, textStatus) {
    alert(XMLHttpRequest.status);

    if(XMLHttpRequest.status === 302) {
        //if it wants to redirect
        window.location = XMLHttpRequest.getResponseHeader("Location");
    }
}

When POST status returns 200 everything works perfect.

The problem is, that when I am getting the 302 status (which I can see I get with firebug), firebug shows me, that there is a GET request called immedidiately after the first Post and I am getting alerted "200" even though the initial POST has a 302 status. Is it normal, that there is a GET shorty after a POST with staus 302 returned, and if yes why am I obviously getting the status of that GET and not the POST?

+1  A: 

It's normal. There's no way to detect 302 status. Browser first redirect and then you get some status but it is not status of page you requested.

ukostin