Reputation: 2758
So I am using backbone.js, and I am trying to save a Model. On the server side I am generating a GUID for the Model that gets received and I am returning that GUID so that way the Model has it on the client side.
My function is as such
this.save({},
{
success: function (model, response) {
alert(response);
},
error: function (model, response) {
alert(response)
}
});
It sends the object to the server, it returns the value I want from the post. It returns a (HTTP/1.1 200 OK
) and yet it calls the error function (which has my proper return value in it)
Any ideas why?
I did the following in the console
JSON.stringify(response)
"{"readyState":4,"responseText":"5dad212e-73bf-4e01-911a-397b81f77022","status":200,"statusText":"OK"}"
So it is getting back the 200 and the guid but not firing success.... I really don't want to just use the error function as that's not what should be firing :p
Thanks in advance!
Upvotes: 2
Views: 1087
Reputation: 1580
Looking at your resposneText
, it seems server is not returning acceptable response - not a proper json
object. Make the server return response like,
{
"guid" : "id_to_be_returned" //,
// and other attributes to be added in the model
}
And make the response type as json
. It should work.
Upvotes: 3