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

后端 未结 4 1873
走了就别回头了
走了就别回头了 2020-12-05 06:13

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

相关标签:
4条回答
  • 2020-12-05 06:50

    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() {} });
    
    0 讨论(0)
  • 2020-12-05 06:51

    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

    0 讨论(0)
  • 2020-12-05 06:54

    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.

    0 讨论(0)
  • 2020-12-05 07:06

    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.

    0 讨论(0)
提交回复
热议问题