使用 fetch 方法分叉 json 文件会在我的代码中触发错误。似乎服务器的响应不正确。进入细节,对于下面的广告模型
//Advertisement model
App.Tasks.Model.Ads = Backbone.Model.extend({
url: "ads/ads.json",
intialize: function () {
},
Next: function () {
var ads = this.get("ads");
return ads[Math.ceil(Math.random(0, ads.legth) * 10)];
}
});
调用时服务器响应应该如何fetch()
。现在如下
{ads: ["1.png", "2.png", "3.png"]}
并且这样做会触发错误回调
//Advertisement model
App.Tasks.Ads = new App.Tasks.Model.Ads();
App.Tasks.Ads.fetch({
success: function (model, response) {
console.log("Success", arguments);
},
error: function (model, response) {
console.log("Error", arguments);
}
});