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?
The handlers are not called if mockjax version 1.5.1 is used. Version 1.5.2 is OK:
MOCK GET: /person/1 > Object {url: "/person/1", type: "GET", isLocal: true, global: true, processData: true…}
MOCK GET: /people > Object {url: "/people", type: "GET", isLocal: true, global: true, processData: true…}
Ann
2
Here is the jsfiddle.