Reputation: 2061
this.model.save(newModel, {error: function (e){
alert("Error trying to save contact: " + e);
console.log(e);
}});
Above is the code that is running on the client side. the server code is
model.update_contact(contact, function(err){
if(err){
res.statusCode = 500;
return res.json({"Database error" : err});
}
return res.end();
});
inspecting the network traffic i see that the server responds with status code 200 but the web page shows the alert message "Error trying to save contact: [Object object]"
p.s the db query is successful
Upvotes: 0
Views: 465
Reputation: 2061
Dumb mistake, my server was not properly returning the object back. Once i added code to return the object everything ran fine.
Upvotes: 0
Reputation: 17168
Backbone expects to get the model's JSON back in response to PUT or POST requests IIRC.
Instead of returning res.end()
try this:
return res.json(contact);
Upvotes: 2