Forking a json file using fetch method triggers error in my code. Seems the response from the server is not right. Into the details, for the ads model below
//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)];
}
});
how should the server response be when calling fetch(). Right now it is as below
{ads: ["1.png", "2.png", "3.png"]}
and doing this triggers the error callback
//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);
}
});
Your server responds with an invalid JSON, the left part in a name/value pair must be a string, which means that
adsshould be wrapped in double quotes:For the complete reference, check http://www.json.org/