Reputation: 129
For example, if I do a destroy on a model and the server returns a 4xx/5xx, the error callback handler is called but the model is removed from the collection anyway. How I do prevent this from happening?
Upvotes: 1
Views: 1707
Reputation: 72868
Backbone is optimistic about this starting in v0.9. From the docs at http://backbonejs.org/#upgrading
Creating and destroying models is now optimistic. Pass {wait: true} if you need the previous behavior of waiting for the server to acknowledge success. You can now also pass {wait: true} to save calls.
So all you have to do is set the {wait: true}
flag in your save:
myModel.save(null, {wait: true});
or in your delete:
myModel.destroy({wait: true})
Upvotes: 8