ajax to get headers,javascript - Get headers Ajax Jquery - Stack Overflow

I try to get the header value "Date" like this but it gives:

xhr.getResponseHeader is not a function

I see the response header in firebug and it exists :S

Maybe no JQuery support? Can this be done in JavaScript instead maybe? must work, I can see the headers...

Code:

function ajaxDate(myUrl){

var res;

var ajaxCall=$.ajax({

type: 'GET',

url: myUrl,

crossDomain: true,

async: false,

cache: false

}).always(function(output, status, xhr) {

//alert(xhr.getResponseHeader("MyCookie"));

console.log(xhr);

console.log(output);

console.log(status);

res=xhr.getResponseHeader('Date');

});

return res;

}

Debug dump from firebug, url: www.google.se:

200 OK 92ms jquery.min.js (line 5)

Response Headers

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

Request Headers

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)

[Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js :: .send :: line 5" data: no] { name="NS_ERROR_FAILURE", message="Failure", result=2147500037, more...}

auto.js (line 52)

console.log(output)

Object { readyState=0, status=0, statusText="[Exception... "Failure"...d :: line 5" data: no]"}

auto.js (line 53)

console.log(status)

error

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值