Sebastian
Sebastian

Reputation: 901

Backbone.js save behaving weird

I create a new model (msg) and save it like below:

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…

Upvotes: 0

Views: 613

Answers (2)

gmcnaughton
gmcnaughton

Reputation: 2293

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

Upvotes: 3

Brian Genisio
Brian Genisio

Reputation: 48137

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.

Upvotes: 3

Related Questions