我试图使用主干'save'方法保存表单数据。我正在使用POST http方法将数据保存到服务器。数据确实保存到服务器,但是在网络控制台中,我看到POST状态显示已取消,但成功创建了数据。 这是js:
var account = Backbone.View.extend({
el: "#account",
events:{
'click button#save' : 'saveList'
},
render: function(id){
value = new accountModel([],{id:id});
},
saveList: function(event){
var values = $('#form').serializeJSON();
value.save(values, {
success: function(value){
console.log(“success”)
},
error: function(err){
console.log('sorry, your record was not saved' + err);
}
});
});
HTML:
<form class="form" id="form">
<table>
<tbody>
<tr>
<label>name</label>
<td><input type="text" name="accountName" maxlength="50"/> </td>
</tr>
<tr>
<label>first</label>
<td><input type="text" name="first" maxlength="50"/> </td>
</tr>
<tr>
<label>last</label>
<td><input type="text" name="last" maxlength="50"/> </td>
</tr>
</tbody>
</table>
</form>
我在success()和error()处设置了一个调试器点,它总是转到错误,但仍然发布数据。我在这里做什么,为什么它表现得如此奇怪?任何想法??
答案 0 :(得分:2)
这里的回答如下:jquery $.post() getting canceled
基本上,event.preventDefault()
功能需要saveList
(之前的其他功能)。