Backbone.js モデルを使用してデータをサーバーと同期しようとしました。ただし、保存方法は機能しません。誰でも理由を見つけるのを手伝ってくれますか?
次のコードは機能します (バックボーン モデルを使用していません)。
var newComment = {
user: user,
createdDate: date,
content: text
}
//TODO send ajax post request to record the data
$.ajax({
url: "comment.php",
context: document.body,
data: newComment,
type: 'POST'
}).done(function(resp) {
console.log("resp", resp);
});
コードが機能しない:
var Comment = Backbone.Model.extend({
urlRoot: 'comment.php'
});
var comment = new Comment();
comment.save({content: text, dsm_line_item_id: "49934380"}, {
succcess: function(model, resp, opt) {
console.log("successfully saved" + resp);
},
error: function(model, resp, opt) {
console.log("error", resp);
}
})