骨干model.save而服务器发送200返回错误:OK [英] Backbone model.save returning error while server sending 200:OK
本文介绍了骨干model.save而服务器发送200返回错误:OK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经定义了以下骨干型号:
I have defined the following Backbone Model:
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.'
}
}
});
我用下面的code在我Backbone.View
I am using the following code in my Backbone.View
// ...
initialize: function() {
this.model = new User();
myUser = {
userName: 'labuser1@example.com',
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);
}
});
}
我收到来自后端以下响应,没有任何反应的数据只发送状态$返回c $ C:
I am receiving the following response from backend, no response data is send only status code is returned:
Request URL : https://server/login
Request Method:POST
Status Code:200 OK
但我得到'错误:[对象的对象]'打印。为什么没有达到成功处理程序,服务器成功地验证用户inspite。请告知,如果需要如何在前端/后端解决这个问题。
But I am getting 'Error: [object Object]' printed. Why it is not reaching success handler, inspite of the server authenticating the user successfully. Please advise how to fix this in frontend / backend if required.
推荐答案
您可以使用此code 数据类型:文本
来解决这个问题。
You can either use this code dataType: 'text'
to fix it
...
this.model.save(myUser, {
dataType: 'text',
success: function () {
...
或正确的内容类型
头设置为应用程序/ JSON
值。
这篇关于骨干model.save而服务器发送200返回错误:OK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文