How to get read data from response header in jquery/javascript [duplicate]
Asked Answered
S

2

11

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....

Samathasamau answered 11/5, 2012 at 9:41 Comment(1)
Ajax request? Or normal page request?Galvanism
M
18

Both XMLHttpRequest and jqXHR (which is the object jQuery wraps around AJAX requests) have a getResponseHeader() method, so in the always() handler (jQuery) or readyState handler (XMLHttpRequest), do this.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.

Melaniemelanin answered 11/5, 2012 at 9:44 Comment(0)
A
5

In JavaScript, using XMLHttpRequest you can do that using getAllResponseHeaders() method.

jQuery also allowing to call that method. See more.

Alannaalano answered 11/5, 2012 at 9:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.