Backbone.Collection.fetch() response headers
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min.js"></script>
<div>
<button type="button" id="fetch-btn">Fetch Collection</button>
</div>
<div>
<textarea rows="10" cols="40" id="results"></textarea>
</div>
JavaScript
$(function() {
var Model = Backbone.Model.extend({});
var Collection = Backbone.Collection.extend({
url: 'https://api.github.com/users/jashkenas/repos',
model: Model,
fetch: function(options) {
var jqXHR = Backbone.Collection.prototype.fetch.call(this, options);
jqXHR.done(function() {
$('#results').val(jqXHR.getAllResponseHeaders());
});
return jqXHR;
}
});
var collection = new Collection();
$('#fetch-btn').click(function() {
collection.fetch();
});
});