0

Hi,
I have this following code:

$('#content-load-target').load(location,function(response, status, xhr) {                   
    if (xhr.status != 200) {
        location.href = '/';
    } else {
        //do something else
    }
});

The response can be either an ajax page or be redirected (if the session has timed out). In case of redirect I want to reload the whole page. The problem is - the response code is always 200. Even if it redirects, it just loads the redirect page and returns 200. How do I properly catch redirects with this?

Thanks

3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by JorgeM
0

I havent had a need to implement this myself, but you should be able to check for other status codes, 302 for instance. In addition, for this to work, you have to make sure that the redirect does not violate security (it is same origin).

Also, in your case, I beleive that the correct operator that you should be using is "!==". In your case every response may result in false because of the operator.

Edited by JorgeM

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.