Backbone model.save() 不调用错误或成功回调 [英] Backbone model.save() not calling either error or success callbacks

查看:21
本文介绍了Backbone model.save() 不调用错误或成功回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新数据库中的记录,因此我正在使用数据定义模型并调用 .save() 方法.触发 PUT 请求并更新数据库条目.问题是既不调用成功也不调用错误回调.可能是什么原因?

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');
    }
});

请求返回 JSON 对象

Request returns JSON object

推荐答案

刚发现类似问题,问题解决了.你必须把一些东西作为第一个参数(我把 null 因为我的模型已经明确地填充了数据)和带有回调的对象作为第二个参数.所以像;

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

这篇关于Backbone model.save() 不调用错误或成功回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆