如何从 jquery/javascript 中的响应头中获取读取数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10548990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get read data from response header in jquery/javascript
提问by Muhammad Usman
Possible Duplicate:
jQuery and AJAX response header
可能重复:
jQuery 和 AJAX 响应头
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 Locationin response header. I want to read that location using JavaScript or jQuery....
如果服务器在响应头中返回数据,我如何读取它。我正在向服务器发送 AJAX 请求。除了响应标头中的Location 之外,它不返回任何内容。我想使用 JavaScript 或 jQuery 读取该位置....
回答by Matt
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')
.
两者XMLHttpRequest
和jqXHR
(其是围绕AJAX请求对象的jQuery套)具有getResponseHeader()
方法,所以在always()
处理程序(jQuery的)或readyState的处理程序(XMLHttpRequest
),做this.getResponseHeader('Location')
。
Bear in mind that if your server alsosends a redirect status code (301/ 302) that redirect will be automaticallyfollowed, and there's no way to access the intermediate-headers returned.
请记住,如果您的服务器还发送重定向状态代码 (301/302),该重定向将被自动跟踪,并且无法访问返回的中间标头。
回答by antyrat
In JavaScript, using XMLHttpRequest
you can do that using getAllResponseHeaders()
method.
在 JavaScript 中,使用XMLHttpRequest
你可以使用getAllResponseHeaders()
方法来做到这一点。
jQuery also allowing to call that method. See more.
jQuery 还允许调用该方法。查看更多。