javascript - Get headers Ajax Jquery -
i try header value "date" gives:
xhr.getresponseheader not function
i see response header in firebug , exists :s
maybe no jquery support? can done in javascript instead maybe? must work, can see 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 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 not p3p policy! see http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 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
the signature of
.always(function(data|jqxhr, textstatus, jqxhr|errorthrown) { });
if mapped method
.always(function(output, status, xhr) {
this line
res=xhr.getresponseheader('date'); // if response success
supposed be
res=output.getresponseheader('date'); // if response fails
looks method failing maps same method errorthrown
instead can write separate fail
method handle or make small change in syntax.
res= output.getresponseheader ? output.getresponseheader.get('date') : xhr.getresponseheader.get('date')
Comments
Post a Comment