Getting the actual URL after a POST which redirected using jquery .ajax()
I finally solved this issue by adding an additional header into all my responses (eg "X-MYAPP-PATH: /Admin/Index").
My javascript could thus be changed to the following:
success: function (data, textstatus, xhrreq) { alert('You are now at URL: ' + xhrreq.getResponseHeader("X-MYAPP-PATH"));},
I still believe however that jquery should be able to give me the current URL, so I consider this a hack.
A better solution is to supply jQuery's ajax with a custom xhr object like this:
var xhr = new XMLHttpRequest();$.ajax({ url: '/url', type: 'post', data: '...', xhr: function() { return xhr; }});
Then you can access the current URL in any callback
success: function () { alert('You are now at URL: ' + xhr.responseURL);}
First try to figure out the status code that is being returned by the redirection (its usually > 300).
success: function (data, textstatus, xhrReq) { //if the status is greater than 300 if(xhrReq.status > 300) { alert('You are now at URL: ' + xhrRequest.getHeader("Location")); } },
One more point to be noted that the order of execution:success\failure --> statusCode function --> Complete