Skip to content

Instantly share code, notes, and snippets.

@Fintan
Created January 15, 2013 07:22
Show Gist options
  • Save Fintan/4536887 to your computer and use it in GitHub Desktop.
Save Fintan/4536887 to your computer and use it in GitHub Desktop.
how-to-save-your-model-to-database-in-backbone-js One of the way to solve this problem is override the save method in your backbone model and send an ajax request from save method.
var Shopper = Backbone.Model.extend({
save: function (options){
var model = this;
$.ajax({
url:'/your/url/',
type:'POST',
dataType: 'json',
data: model.toJSON(),
success: function (object, status){
//things to do if model saved successfully.
}
})
}
});
var shopper = new Shopper();
shopper.save();
//http://jineshpaloor.wordpress.com/2012/05/23/how-to-save-your-model-to-database-in-backbone-js/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment