javascript - Backbone Fetch Request is OPTIONS method -
i have backbone collection object following url "http://localhost:8080/api/menu/1/featured". trying perform fetch operation retrieve collection url , parse it. however, on server side, method type see request options. server suppose support method. not sure how backbone figuring out method type use, , why changes options method type randomly sometimes. using node.js server process request. code below pretty did.
var featuredcollection = backbone.collection.extend({ model:featuredcontent, url:function () { return url_featured; }, parse:function (response) { console.log(response); return response; } }); var featuredcollection = new featuredcollection(); featuredcollection.fetch();
please help, thanks!
it's been awhile, remember coming across before. there's 2 things be: backbone default tried restful api calls backend, means get, post, put, , delete.
many backends weren't built real rest support , support , post. when backbone sends put or delete command browser (not backbone) automatically sends options request first see if it's allowed make these kinds of requests. if server answers improperly call fail , backbone won't anything.
to around set backbone.emulatehttp = true;
or have server answer options calls. see documentation more info: http://backbonejs.org/#sync-emulatehttp
the other issue you're making ajax requests cross-domain / sub-domain , need enable cors. includes answering options requests.
Comments
Post a Comment