Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Created July 3, 2012 05:58
Show Gist options
  • Save juliocesar/3037975 to your computer and use it in GitHub Desktop.
Save juliocesar/3037975 to your computer and use it in GitHub Desktop.
Getting headers on Backbone.Collection.prototype.fetch
# Actually more of an example of how to pick headers value and put them in Backbone collections.
class HeadersAwareCollection extends Backbone.Collection
parse : (resp, xhr) ->
@total = xhr.getResponseHeader('X-Total-Results')
super
# Alternatively, call `xhr.getAllResponseHeaders()`, parse the text, and add the whole object to
# the collection.
# Thanks @philoye for pointing out that `parse` is a better fit than `fetch` for this!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment