Find out where Jquery ajax request gets redirected to Find out where Jquery ajax request gets redirected to ajax ajax

Find out where Jquery ajax request gets redirected to


If possible, have your server set a header on those pages (the destination pages, not the redirecting one), for example set a "current-location" header, then you can do this:

$.ajax({    url: 'http://example.com/makeThing',    dataType: 'html',    type: 'POST',    data: {        something:someotherthing    },    complete: function(request, status) {        var location = request.getResponseHeader("current-location");    }});

Yes, this is a bit hacky, but since the redirect is handled internally in the XmlHttpRequest object (an event to which you can't access), you don't have much choice.

You can check the spec, this is the intended behavior for XmlHttpRequest:

If the origin of the URL conveyed by the Location header is same origin with the XMLHttpRequest origin and the redirect does not violate infinite loop precautions, transparently follow the redirect while observing the same-origin request event rules.


This may not help your particular situation, but when I had the same problem I noticed the page I ended up on after the redirect had a clue in the HTML:

<meta property="og:url" content="THE_URL_OF_THE_PAGE" />

Some pages have script snippets in them used for adding Facebook commenting, and those can sometimes contain the current URL too. Or even as blatantly as this:

<a href="http://www.facebook.com/sharer.php?u=THE_URL_OF_THE_PAGE">


Why don't you just plug the URL 'http://example.com/makeThing' into your browser and see where you end up?