I’m new to backbone and I am trying to send a delete command. I’m using the post modification option but the delete only send the method. Example below:
Backbone.emulateHTTP = true;
Backbone.emulateJSON = true;
ProductImageModel = Backbone.Model.extend({
initialize : function() {
},
url : "/products/ajaximage",
});
//Later called using
var image = new ProductImageModel({id: id});
image.destroy();
The problem is, the id is never passed, and all that appears in the $_POST is this:
Array
(
[_method] => DELETE
)
Is there a way to pass the id in the delete?
In reviewing the annotated source, and looking at your code… You’re overriding the
Model.urlmethod with a static property. TheBackbone.Model.urlmethod looks like this:Which is generating your URL for you on the fly based on whether your model is new, or not.
What you should be doing, instead of defaulting your
Model.urlproperty to'/products/ajaximage'is defaulting theModel.urlRootproperty to'/products/ajaximage'. That should allow you to executeModel.destroy()and get the model’s ID as part of the request url to the server, so you know which model you need to delete.