I'm trying to fetch a single model and a collection of models from mockjax (jsfiddle):
var Person = Backbone.Model.extend({ urlRoot: "/person" }),
person,
People = Backbone.Collection.extend({ url: "/people", model: Person }),
people;
// Fetching a single model
$.mockjax({
url: "/person/*",
responseText: { id: 1, name: "Ann", age: 10 }
});
person = new Person({ id: 1 });
person.fetch({
success: function () {
console.log(person.get("name"));
}
});
$.mockjaxClear();
// Fetching a collection of models
$.mockjax({
url: '/people',
responseText: [
{ id: 1, name: "Ann", age: 10 },
{ id: 2, name: "Bill", age: 20 }
]
});
var people = new People();
people.fetch({
success: function () {
console.log(people.length);
}
});
$.mockjaxClear();
The console output shows that mockjax received the GET request, but the success handlers haven't been called:
MOCK GET: /person/1
MOCK GET: /people
Why are my success handlers not called?