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.'
}
}
});
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);
}
});
}
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
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.