Reputation: 3341
I have just started exploring Backbone.js.
Upon submission of a form I would like Backbone.js to save the details to database.
How can I go about this?
Upvotes: 7
Views: 17387
Reputation: 32202
Unless you are using HTML5 local storage in the client the responsibility for saving to the database is not with backbone.js. Backbone will talk to the server via Backbone.sync using a REST type request. Effectively it will make an http POST request to save a new record or an http PUT request to update a current record.
The difference between a new record and a current record is that the :id field of the record is not set for a new record and is set for an old record.
If you want a tutorial using Ruby Rails as your backend solution then you can look at this tutorial.
http://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by-example/
However you can use any backend server such as PHP, Java, Django etc as long as they meet the requirements of the REST interface that backbone.js uses.
If you overide Backbone.sync you can also get backbone.js to interface to pretty much any legacy http protocol as well.
Upvotes: 13