Created
January 15, 2013 07:22
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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