开发者

Backbone.js save behaving weird

开发者 https://www.devze.com 2023-04-12 16:49 出处:网络
I create a new model (msg) and save it like below:开发者_如何学Go msg.save({}, {success: this.createSuccess, error: function(model, response){

I create a new model (msg) and save it like below:开发者_如何学Go

msg.save({}, {success: this.createSuccess, error: function(model, response){
  console.log('nay', response);
}});

Now the server returns status: 200 and statusText: "OK" but still the error callback is called.

The model has no validation nor does the server (Express.js).

What could I've overlooked?

I'm using the latest version of Backbone and Express…


Are you returning anything in your body? If all you are returning is 200 OK in the head, then you will get an error. You should return the JSON representation of the saved item (including the id, which is really important for updates/deletes later) from your server.


If you want to return an empty response, the response code should be 204 No Content. See https://stackoverflow.com/a/9104241/157943.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号