我已经定义了以下骨干型号:骨干model.save返回错误:OK
var User = Backbone.Model.extend({
url: "/login",
contentType: "application/com.example.auth+json",
defaults: {
userName: '',
password: ''
},
validate: function(attrs){
if(!attrs.userName){
return 'Please fill username field.'
}
if(!attrs.password){
return 'Please fill password field.'
}
}
});
我用我Backbone.View下面的代码
// ...
initialize: function() {
this.model = new User();
myUser = {
userName: '[email protected]',
password: 'abcd_1234',
};
}
onSubmit: function() {
this.model.save(myUser, {
success: function() {
alert('You are authenticated');
Backbone.trigger('Authenticated', {source: 'LOGIN'});
},
error: function (model, error) {
alert('Error: " + error);
}
});
}
我从后端接收以下响应,没有响应数据仅发送状态码返回:
Request URL : https://server/login
Request Method:POST
Status Code:200 OK
B我得到'错误:[对象对象]'打印。为什么它没有到达成功处理程序,尽管服务器验证用户成功。如果需要,请告知如何在前端/后端解决此问题。
谢谢,我添加了代码dataType:'text',问题已修复。 – Tarun