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?


Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.