I have a server that works with a header ETag. Backbone refers to the API for the first time: everything is good, the response received and parse. Second time: backbone sends to the server ETag, in response receives NotModified. And Backbone trying to parse this response, resulting in a collection called reset.
Is there any way around it resets the collection?
The method of adding the option to add in the fetch method will not work. Since I need to completely refresh the collection, if I came to the server's response.
var recommendCollection = Backbone.Collection.extend({
model : Event,
etag : null,
urlRoot : '/api/users',
initialize: function() {
this.etag = null;
},
parse: function(response) {
return response.data;
},
url : function () {
return (this.urlRoot + "/"+window.me.get('id')+ "/recommendation");
},
beforeSend : function (jqXHR, settings) {
jqXHR.setRequestHeader('if-none-match', this.etag);
},
complete : function (jqXHR, textStatus) {
if (jqXHR.status == 200 || jqXHR.status == 304) {
this.etag = jqXHR.getResponseHeader('ETag');
}
},
update : function () {
this.fetch({
beforeSend : this.beforeSend.bind(this),
complete : this.complete.bind(this),
data : {
cityId : window.me.get('cityId'),
}
});
}