request handler for ‘/donut’
class DonutHandler(webapp2.RequestHandler):
def get(self):
self.response.write("{id: 42, name: 'bob', age: 12}")
Javascript:
var Donut = Backbone.Model.extend({
url: '/donut',
urlRoot: '/donut'
});
donut = new Donut()
donut.fetch({success: function() {
console.log('ok');
},
error: function(collection, response) {
console.log('error on -> ' + response.responseText);
}
});
error on -> {id: 42, name: 'bob', age: 12}
I expected instead that ‘ok’ would be logged to the console and that my donut would now have attributes age, id and name.
That happens because your response is not a valid JSON string.
Try to send this as a response: