Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone model.save() not calling either error or success callbacks

Tags:

backbone.js

I'm trying to update a record in DB so I'm defining model with data and calling .save() method. The PUT request is triggered and the database entry is updated. The problem is neither success or error callbacks are called. What could be the cause?

sessionsModel.save({     error: function() {         alert('test');     },     success: function () {         alert('test');     } }); 

Edit: Request returns JSON object

like image 649
marcin_koss Avatar asked Jul 04 '12 03:07

marcin_koss


2 Answers

While searching on this, I first landed on this SO thread which did not work for me, but seemed to work for other, later on I bumped into this link, where some one had tried null instead of {} as the first parameter.

this.model.save(null, {     success: function (model, response) {         console.log("success");     },     error: function (model, response) {         console.log("error");     } }); 

so, this worked for me. Hope this helps you too.

like image 27
Yasser Shaikh Avatar answered Oct 04 '22 08:10

Yasser Shaikh


Just found similar problem where the issue was solved. You have to put something as first parameter (I put null since my model was already populated with data explicitly) and object with callbacks as second. So something like;

sessionsModel.save(null, {success:function() {} }); 
like image 78
marcin_koss Avatar answered Oct 04 '22 08:10

marcin_koss