javascript - Why does backbone fetch not work for me -
i trying solve issue backbone fetch. getting 'failed fetch!' in console.
i think not issue connected same origin policy because json returned server , according jsonlint valid
[{"name":"spanish a1"},{"name":"spanish a2"}]
code in gist: https://gist.github.com/konradmasalski/bfaac7d481d890ca5c54
update - code
var fishe = {}; fishe.deck = backbone.model.extend({ initialize: function () { alert("welcome world"); } }); fishe.deckcollection = backbone.collection.extend({ model: fishe.deck, url: 'http://fishes.localhost/deck.json', sync: function (method, model, options) { console.log('syncing'); var params = _.extend({ type: 'get', datatype: 'jsonp', url: this.url, success: function (data, textstatus, jqxhr) { console.log(data) }, error: function (jqxhr, textstatus, errorthrown) { this.model.set($.parsejson(jqxhr.responsetext)); } }, options); return $.ajax(params).done(function () { console.log('finished') }); } }); fishe.data = {}; fishe.data.decks = new fishe.deckcollection(); fishe.data.decks.fetch({ success: function () { console.log(fishe.data.decks.tojson()); }, error: function () { console.log('failed fetch!'); } });
Comments
Post a Comment