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

25,148

Solution 1

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() {} });

Solution 2

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.

Solution 3

Your server must return a JSON object. If the response is not a JSON object, the callbacks will not fire. Check this solution https://stackoverflow.com/a/22176044/1579718

Solution 4

I was suffering this issue - but was struggling because my server was responding with a valid JSON object (the model) and I was already using null in my save call.

As I (eventually) found, before the success callback is fired, the returned model is passed through the validate method. In my case I had a (obvious when you're looking in the right place) problem which caused the returned model to be deemed invalid and subsequently prevent the success callback.

Whilst I appreciate this doesn't help the OP, I post this in the hope it helps someone else having the same issue.

Share:
25,148
marcin_koss
Author by

marcin_koss

Updated on March 14, 2020

Comments

  • marcin_koss
    marcin_koss about 4 years

    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