I get an error response from the .save() function. The server side php returns me a text and successfully saves the url into database. When I inspect the response I can see the text returned by PHP, however I do not understand why it turns in the error callback. What could be the reason?
urlToAdd.save({}, {
success: function () {
console.log("In here");
},
error: function (model, response) {
console.log(model.toJSON());
console.log(response);
console.log("Not in here");
}
});
The server responds with:
HTTP/1.1 200 OK
Date: Sat, 19 May 2012 21:31:27 GMT
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.6
X-Powered-By: PHP/5.3.6
Content-Length: 96
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
X-Pad: avoid browser bug
Hmmm… Even though the response is valid, the content-type tells the whole story… The expected content-type should be application/json. If your response isn’t JSON, error will be invoked every time. If you have a way to encode your response as JSON, you should see the success invoked instead of the error.