Javascript 获取Ajax Jquery的标题
我尝试像这样获取标题值“Date”,但它给出:Javascript 获取Ajax Jquery的标题,javascript,jquery,ajax,Javascript,Jquery,Ajax,我尝试像这样获取标题值“Date”,但它给出: xhr.getResponseHeader is not a function 我在firebug中看到响应头,它存在:S 也许没有JQuery支持?这可以用JavaScript来代替吗?必须工作,我可以看到标题 代码: firebug的调试转储,url:www.google.se: 200 OK 92ms jquery.min.js(第5行) 响应头 Alternate-Protocol 80:quic Cache-Control p
xhr.getResponseHeader is not a function
我在firebug中看到响应头,它存在:S
也许没有JQuery支持?这可以用JavaScript来代替吗?必须工作,我可以看到标题
代码:
firebug的调试转储,url:www.google.se: 200 OK 92ms jquery.min.js(第5行) 响应头
Alternate-Protocol 80:quic
Cache-Control private, max-age=0
Content-Encoding gzip
Content-Type text/html; charset=UTF-8
Date Fri, 09 Aug 2013 00:57:43 GMT
Expires -1
P3P CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
Server gws
Set-Cookie PREF=ID=e6503cda76a:FF=0:TM=1376009863:LM=1376009863:S=pByclnZqvnZs2k5S; expires=Sun, 09-Aug-2015 00:57:43 GMT; path=/; domain=.google.se, expires=Sat, 08-Feb-2014 00:57:43 GMT; path=/; domain=.google.se; HttpOnly
Transfer-Encoding chunked
x-frame-options SAMEORIGIN
x-xss-protection 1; mode=block
请求头
Accept */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Host www.google.se
Origin http://localhost/
Referer http://localhost/
User-Agent ....
console.log(xhr)
console.log(输出)
console.log(状态)
签名始终是
.always(function(data|jqXHR, textStatus, jqXHR|errorThrown) { });
如果映射到您的方法
.always(function(output, status, xhr) {
这条线
res=xhr.getResponseHeader('Date'); // If response is a success
应该是
res=output.getResponseHeader('Date'); // if response fails
看起来您的方法失败了,它将相同的方法映射到errorhorn
相反,您可以编写一个单独的fail
方法来处理它,或者对语法进行一些小的更改
res= output.getResponseHeader ? output.getResponseHeader.get('Date')
: xhr.getResponseHeader.get('Date')
为
.always
报告两个不同的签名,jquery xhr对象是第一个或第三个参数-您是否尝试过.always(函数(xhr、状态、输出)
?@PHPglue:您没有。请参阅,特别是弃用通知。。始终
替换。完成
作为ajax请求完成后要处理的回调,而不管其结果如何。成功被取消?测试成功,但没有成功。我将对此进行测试,听起来非常不错。我的方法失败,但使用您的解决方案,它会给我TypeError:output.getResponseHeader.get不是一个函数。您可以尝试在该回调中放置调试点并检查参数吗console.log(output)向我显示有一种方法可以获取所有响应头getAllResponseHeaders(),但这将返回一个空字符串:/Maybe该对象仅在ajax失败时可用
.always(function(output, status, xhr) {
res=xhr.getResponseHeader('Date'); // If response is a success
res=output.getResponseHeader('Date'); // if response fails
res= output.getResponseHeader ? output.getResponseHeader.get('Date')
: xhr.getResponseHeader.get('Date')