I want to write event (in jquery) that occurs when any ajax is complete. I need this because I use forms authentication and when user is logged out and ajax call is made - div (not all page) is reloaded with login page. I want to make redirect instead. So how can I catch successfull call of ajax request? What have I tried:
$(document).ajaxComplete(function (event,xhr,data) {
var url = data.url;
if (xhr.status == 302) {
window.location = '~' + url;
}
});
The transparent redirection is the part of XMLHttpRequest specification. You can't prevent the redirection.
If the server sends a redirect (301, 302), the redirect is transparently followed by the browser. The response to the second request (ex 200) is what is exposed to your app.