Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reponse headers not available in success callback #35

Open
brianberlin opened this issue Nov 9, 2015 · 1 comment
Open

Reponse headers not available in success callback #35

brianberlin opened this issue Nov 9, 2015 · 1 comment

Comments

@brianberlin
Copy link

i'm having an issue getting a header in ampersand-rest-collection success callback after updating to v5.0.0.

http://cl.ly/image/011Y1q1Y3s1g

@dhritzkiv
Copy link
Member

You may have figured it out by now, but to answer your question:

xhr in this case is the browser default return value for an XMLHttpRequest instance. This is returned by calling view.collection.fetch(). In order to retrieve headers from an XHR instance, you need to call xhr.getAllResponseHeaders() (or xhr.getResponseHeader(header) to get a specific header.)

However, more conveniently, in your success callback, the last argument, the response object, has those headers pre-populated for you. So in order to access the count header you could do this:

view.collection.fetch({
    success: function(collection, json, response) {
        var count = response.headers.count;
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants