I want to override the collection for development purpose (return fake json results from a JSON var or JSON file). But I got error doing below with url
http://jsfiddle.net/qhoc/uZhM8/
GET http://fiddle.jshell.net/_display/[object%20Object],[object%20Object] 404 (NOT FOUND)
However, if I use parse, it seems the parse got executed right after initialize because of both my console.log results show the same thing
http://jsfiddle.net/qhoc/uZhM8/1/
So how to override the url so that fetch can add another JSON at some point (in separate function)?
The
urlof a collection is supposed to return a URL which will be used with$.ajaxto talk to the server:Your
urlmethod is returning an array and Backbone is treating that like a URL string, hence the odd looking URL that produces your 404.You have some options:
syncto use some inlined JSON instead of a$.ajaxcall.fetchto use some inlined JSON instead of callingsync.If you’re only concerned about fetching data then all three should work, if you need to simulate saves or deletes, then you’ll probably end up overriding
sync.