I have a link which dispatches an Ajax POST to perform an action. If the user is not yet signed in, the action method returns a 302 redirect to the login page. If this happens, I want to catch the redirect, so that I can display the login form in a lightbox.
However, it seems that jQuery follows the redirect without returning control or calling a callback function. In the code below, the alert of 302 redirect is never called, and by the time the dataFiler function is called, the data is the content of the login page.
How can I see that the page has sent a 302 redirect, and branch to a different action?
$.ajax(url,
{
data: postArguments,
type : "POST",
success: function (data) { alert(' success function'); },
statusCode:
{
302: function () { alert(' received redirect 302'); },
301: function () { alert(' received redirect 301'); }
},
dataFilter: function (data, type) { alert('got data ' + data); return data; }
});