Possible Duplicate:
jQuery and AJAX response header
If the server is returned data in response header how I can read it. I am sending an AJAX request to a server. It does not return anything but the Location in response header. I want to read that location using JavaScript or jQuery....
In JavaScript, using
XMLHttpRequest
you can do that usinggetAllResponseHeaders()
method.jQuery also allowing to call that method. See more.
Both
XMLHttpRequest
andjqXHR
(which is the object jQuery wraps around AJAX requests) have agetResponseHeader()
method, so in thealways()
handler (jQuery) or readyState handler (XMLHttpRequest
), dothis.getResponseHeader('Location')
.Bear in mind that if your server also sends a redirect status code (301/ 302) that redirect will be automatically followed, and there's no way to access the intermediate-headers returned.