【发布时间】:2016-10-30 18:28:30
【问题描述】:
您好,我正在尝试将模型保存到数据库。我只是输入标题的值来保存它,因为我的 id 是自动递增的。我已经尝试过了,但没有奏效。谁能帮帮我?
我需要在我的主干模型中指定什么 urlRoot 或 url 函数?我需要指定收藏的网址吗?
型号:
var DocumentUser = Backbone.Model.extend({
urlRoot: '/app_dev.php/user'
});
这是我的保存功能:
save: function(method, model, options) {
this.model = new DocumentUser();
this.model.save({
title: $('#title').val()
}, {
success: function(model, respose, options) {
console.log('The model has been saved to the server');
},
error: function(model, xhr, options) {
console.log('Something went wrong while saving the model');
}
});
}
【问题讨论】:
标签: javascript jquery ajax backbone.js