The problem is surely in this line:
cliente.destroy();
The method destroy
what it does is, using Backbone.sync , try to destroy that model on the server by means of a request DELETE
, returning the object XMLHttpRequest
of that request or false
if the object referenced by that model is not yet saved on the server.
If you are using a API Rest
to update your data on the server, add the URL
to the model so that Backbone
knows where to update that data (in this parameter it is expected or the representation String
of a URL
or a function):
var miModelo = Backbone.Model.extend({
url: "/url/a/la/api/rest/"
});
If on the other hand you are not using a API Rest
and you are saving the data locally (using localStorage or sessionStorage ) without using an adapter such as Backbone.localStorage , then try to make an override parameter sync to rewrite each method CRUD with your own implementation:
If you read the entry of Backbone.sync
, you can see each of the parameters that sync
receives:
- method: will be the one that contains the string representation of the CRUD method
- model: will come the model you want to save, delete, update, etc ...
- options: (optional parameter) is where the success and error callbacks will be contained
var miModelo = Backbone.Model.extend({
sync: function(metodo, modelo, opciones) {
switch (metodo) {
case "create":
break;
case "read":
break;
case "update":
break;
case "delete":
break;
}
}
});