开发者

Problem reading the XMLHttpRequest.status when redirecting

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
        wind开发者_运维问答ow.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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜