Reputation: 891
I'm trying to save model with this code:
this.model.save({},
{
success: function (model, response) {
alert("ok");
},
error: function (model, response) {
alert("error");
}
});
I catch the error callback. But my REST API returns a 200 status:
Content-Length:0
Content-Type:application/json
Status code:200
On the server side I have following code:
@RequestMapping(value = "{id}/image/{type}", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public void uploadImage(..) {
response.setStatus(HttpStatus.OK.value());
response.setContentType("application/json");
}
Why backbone.js call error callback instead success?
Upvotes: 0
Views: 97
Reputation: 566
Looking at the annotated source for Backbone http://backbonejs.org/docs/backbone.html, save appears to expect an object in response from the server. If you change your uploadImage method so that it does not return void, (returning an empty object {} would likely work), the success handler should be triggered.
Upvotes: 2