ers.
I am trying to implement my custom collection where I overwrite fetch method. Later I will use this collection to extend my Backbone collections.
var BaseCollection = Backbone.Collection.extend({
fetch: function (options) {
options = options || {};
if (!options.headers) {
options.headers = {
'Content-type': 'application/json',
'Accept': 'application/json',
'Authorization' : "Basic: user:password"
};
}
options.reset = true;
console.log('I am extended fetch method');
return Backbone.Collection.prototype.fetch.call(this, options);
}
});
var ShipsCollection = BaseCollection.extend({
url: 'http://localhost:3000/v1/ships',
model: Ship
});
But when I call fetch for my collection I can not see headers were sent to the server:
var shipsCollection = new ShipsCollection();
shipsCollection.fetch();
How can I extend fetch to be able send custome headers ? I do not want to overwrite sync.