Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js destroy problem

i'm having a problem with destroy method. I can save and see the HTTP activity in my firebug but when i use destroy method i can't see anything. Can anybody explain why ?

Backbone.emulateHTTP = true;
Backbone.emulateJSON = true;

var Hacker = Backbone.Model.extend({
      url:"http://localhost/backbone051/save.php",
});

var hacker = new Hacker();
hacker.set({name:"Herman Ganteng",age:"23"});
hacker.destroy(); //doesn't show any activity :(
like image 613
Herman Taniwan Avatar asked Dec 12 '25 00:12

Herman Taniwan


1 Answers

Your model has no Id field. Typically the Id would be populated by a previous fetch call. In this trivial example you could hard code one like this:

var Hacker = Backbone.Model.extend({
     id: "something",
     url:"http://localhost/backbone051/save.php",
});

This will result in a POST at the url specified.

like image 125
mfalto Avatar answered Dec 14 '25 13:12

mfalto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!