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

佐手、 提交于 2019-11-26 16:44:53

问题


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


回答1:


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.




回答2:


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

jQuery also allowing to call that method. See more.



来源:https://stackoverflow.com/questions/10548990/how-to-get-read-data-from-response-header-in-jquery-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!