0

I was trying to get the value of content-length header using jQuery.

var XHRObj = $.ajax({
    type:'HEAD',
    url:'https://www.udacity.com/public-api/v0/courses',
    success:function(data) {
        console.log( XHRObj.getResponseHeader('content-length') )
    }
});

It's getting as null. I checked the URL response headers. It has content-length header.

Arun Prakash
  • 421
  • 2
  • 6
  • 20
  • Maybe it's a case-sensitive issue? What about `data.length`? Might not be very accurate though. – MinusFour Aug 27 '15 at 05:19
  • Is it possible to get content-length header value without the json gets fully loaded? The size of my json is big, I just want to know the size from the header. – Arun Prakash Aug 27 '15 at 05:20
  • Oh right, I just noticed you are doing a HEAD request. Does it work with `Content-Length` instead of `content-length`? – MinusFour Aug 27 '15 at 05:23
  • I checked using Content-Length . It's coming as null. – Arun Prakash Aug 27 '15 at 05:24
  • Check all response headers then: ` `console.log(XHRObj.getAllResponseHeaders());` – MinusFour Aug 27 '15 at 05:25
  • I tried. I got error message as Uncaught TypeError: XHRObj.getResponseHeaders is not a function Then, I tired console.log(XHRObj.getResponseHeader('Content-Length')); It's showing as null – Arun Prakash Aug 27 '15 at 05:29
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/88058/discussion-between-arun-prakash-and-minusfour). – Arun Prakash Aug 27 '15 at 05:29
  • 1
    check this one http://stackoverflow.com/questions/14686769/xmlhttp-getresponseheader-not-working-for-cors – Muhammad Usman Aug 27 '15 at 05:42

0 Answers0