After a jQuery.ajax()
call jqXHR.getAllResponseHeaders()
won't return all the headers. The server responded with the following headers:
Connection: keep-alive Content-Length: 64 Content-Type: application/json X-My-CustomHeader: whatever
getAllResponseHeaders()
returned only:
Content-Type: application/json
What am I doing wrong?
Example
var request = { 'url': 'http://api.someExternalDomain.com/resource/', 'type': someMethod, 'success': function(data, textStatus, jqXHR) { console.log(jqXHR.getAllResponseHeaders()); } }; $.ajax(request);
svenyonson called this out in the comments, but for me it was the answer, so I'm elevating it. If you're doing CORS, the server has to be explicit about what headers the client is allowed to read. If you want to read X-My-CustomHeader
in javascript, then this header should be in the server response:
Access-Control-Expose-Headers: X-My-CustomHeader
More detail here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With