0

I'm putting together an app using WP-API with an Angular frontend. I'm developing locally, with the data I'm trying to use loaded in from a remote server. Doing a $resource request for all posts works great.

But, I'm trying now to get the result of the X-WP-TotalPages header and can't figure out how to do it. Here's the code as it stands:

var request = function() {
    var fullRoute = 'http://dylangattey.com/wp-json/posts/';
    var defaultGet = {
        method: 'GET',
        transformResponse: function(data, headers){
            response = {};
            response.posts = JSON.parse(data);
            response.headers = headers();
            console.log(headers['X-WP-TotalPages']);
            return response;
        }
    };
    return $resource(fullRoute, {}, {
        get: defaultGet,
           query: defaultGet
    });
};

// This gives me back the first 10 posts
request().query();

Chrome and curl both show that X-WP-TotalPages should be equal to 2 as a header. However, it just logs undefined.

Am I missing something? No matter whether I use $http or $resource I get the same result. I also have the same issue whether I use a remote site or a local WP installation on localhost. Really, I just want to know the total number of pages or even just the total number of posts for a given request, so if there's a better way to do it, I'd love to know.

Dylan Gattey
  • 1,713
  • 13
  • 34

1 Answers1

0

You probably need to control the access to the specific headers you want on the server side.

See this thread for a brief discussion, or MDN on Access-Control-Expose-Headers.

Community
  • 1
  • 1
doldt
  • 4,466
  • 3
  • 21
  • 36
  • Even though I can see the headers in Chrome? I don't understand why the headers would be needed just for Angular. Also, running it on the same host (localhost for example) also causes the same issue. Which makes me think it's not CORS – Dylan Gattey May 19 '15 at 23:33