Catching 302 FOUND in JavaScript

The accepted answer does not work for the reasons given. I posted a comment with a link to a question that described a hack to get round the problem of the 302 being transparently handled by the browser:

How to manage a redirect request after a jQuery Ajax call

However, it is a bit of a dirty hack and after much digging around I found what I think is a better solution – use JSON. In this case, you can make all responses to ajax requests have the code 200 and, in the body of the response, you add some sort of JSON object which your ajax response handler can then use in the appropriate manner.

Leave a Comment