I have a jQuery post call like the following:
$.post('/Controller/_PartialAction', { 'param1': data }, function(result) { });
That’s fine and it all works, except when a user’s authentication cookie expires.
What happens is, there is already stuff in there that will redirect /Controller/_PartialAction to the login page, BUT the partial action in this case is a partial view, instead I want to redirect a full view.
So it is already redirecting that to the login page, but I want to redirect a different page, say I want to redirect to /Controller/Index. Is there any way to specify an error path or redirect path in an ajax/jQuery call?
I.E., something like this (This doesn’t exist, but like what i’m trying to do)
$.post({success}, {redirect}, {error}, {data}, {function})
So basically, how can I do a jQuery/ajax post call with a different url for errors so I can redirect to that one?
edit
What is being redirected is the ajax call itself. So I can’t redirect it from the controller.
I’m not entirely sure what you’re after, but (based on http://api.jquery.com/jQuery.post/) could you use the underlying $.ajax (http://api.jquery.com/jQuery.ajax/) and set an
errorfunction?Or can you test for the expiration of the cookie in the success callback, then redirect based on the result of that test.