我有一个RESTful服务,当我尝试保存新记录时,会进行唯一的电子邮件检查.当它失败时,我返回一个400错误代码以及一个带有"errors"值的JSON消息.
不幸的是,我的保存错误回调似乎没有被解雇.有什么建议?
var nRecord = new RecordModel(values);
nRecord.save({
wait: true,
error: function(model,response){
console.log('error2');
obj.errorHandler(model,response);
},
success: function() {
console.log('success2');
obj.alert('Information saved!','Record Created!','success');
// if there were no errors, clear the list
$('#record-form :input').val('');
}
});
Run Code Online (Sandbox Code Playgroud)
"Error2"永远不会显示在控制台中.思考?
您似乎将错误处理程序和其他选项作为模型属性传递并保存到模型中.尝试将null作为第一个参数传递给save函数.希望这会使它工作:)
nRecord.save(null,{
wait: true,
error: function(model,response){
console.log('error2');
obj.errorHandler(model,response);
},
success: function() {
console.log('success2');
obj.alert('Information saved!','Record Created!','success');
// if there were no errors, clear the list
$('#record-form :input').val('');
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1274 次 |
| 最近记录: |