'/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}
相反,我希望将“ok”记录到控制台,并且我的甜甜圈现在将具有属性年龄、id 和名称。