Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS $http object not showing all headers from response

I'm having a problem with AngularJS's $http service not returning all of the headers from the API I'm polling. Here's what I've got:

$http({
    method: 'POST',
    withCredentials: true,
    url: 'http://api.mydomain.com/query',
    data: JSON.stringify(parameters)
})
.success(function(data, status, headers, config){
    ... // setting some scope parameters based on data
    console.log(headers());
})

I can tell through the network tab in Chrome that a bunch of response headers are being returned by the API (I'm particularly interested in the X-Pagination-Total-Items header).

Here's a screenshot of the network tab from the request: Chrome's Network Panel

But the console.log statement above (which should output all headers) only returns two: Console Log...missing headers!

Any idea what's going on? How do I actually access all of the headers coming back from the AJAX call?

Thanks,

-Nate

like image 924
Nathan Rutman Avatar asked Feb 07 '14 18:02

Nathan Rutman


1 Answers

Turns out that the Access-Control-Expose-Headers cannot accept a wildcard. We needed to specify exactly which headers the client should have access to, and then it worked.

like image 119
Nathan Rutman Avatar answered Oct 19 '22 12:10

Nathan Rutman