This is an old post, but it is highly regarded by Google, so I will add my solution.
If you have control over the ajax response, you can add a header to the response with the final URL.
In PHP, it will be something like:
header('X-final-url: /some/other/location') .
Then in jquery you can access this value with:
var finalUrl = jqXHR.getResponseHeader('X-final-url');
I am adding a header to Symfony using a kernel listener:
Service
app.kernel.response_metadata_populator: class: AppBundle\Listeners\ResponseMetadataPopulator tags: - { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }
Listener class
class ResponseMetadataPopulator { public function onKernelResponse(FilterResponseEvent $event) { $response = $event->getResponse(); $response->headers->set('X-FINAL-URL', $event->getRequest()->getRequestUri()); } }
jxmallett
source share