I am facing an issue with fetching a model using model.fetch();
. The model's urlRoot is set to "/backend/item" in my application, but currently I do not have access to the back-end environment. To work around this, I decided to mock the results by adding a route in my router:
"backend/item/:id": "data_getItem"
and defining a function:
data_getItem: function(id) {
console.log("data_getItem: "+ id);
return {
animals: [
{
name: 'flying cat',
type: 'none'
}
]
};
}
However, when I run the application, I can see an ajax call being made to "http://127.0.0.1:8000/backend/item/1", but the console is empty and I receive an error (the fetch function redirects me to the error callback). I'm wondering why this is happening and how I can successfully mock the back-end data.
EDIT @rjz provided some help on achieving what I want to do, but I am curious if an ajax call can be intercepted by Backbone router. My intuition suggests that it might not be possible because ajax calls cannot execute client-side Backbone code, making the concept of router irrelevant in this scenario. Am I correct?..