如何从jquery / javascript中的响应头读取数据 [英] How to get read data from response header in jquery/javascript

查看:188
本文介绍了如何从jquery / javascript中的响应头读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

jQuery和AJAX响应头

如果返回服务器响应头中的数据我怎么读它。我正在向服务器发送一个AJAX请求。除响应标头中的位置外,它不会返回任何内容。我想使用JavaScript或jQuery读取该位置....

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

推荐答案

两者 XMLHttpRequest jqXHR (这是jQuery包装AJAX请求的对象)有一个 getResponseHeader()方法,所以在 always() handler(jQuery)或readyState handler( XMLHttpRequest ),执行 this.getResponseHeader('Location')

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

请记住,如果您的服务器发送重定向状态代码(301/302),则重定向将 自动跟随,然后是无法访问返回的中间标头。

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.

这篇关于如何从jquery / javascript中的响应头读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆