Reputation: 3884
Mockjax setup:
$.mockjax({
url: "/api/get",
responseTime: 100, // default: 500
dataType: "json",
data: { action: "all" },
proxy: "data.json",
status: 400
});
The call to mockjax:
$.ajax({
url: '/api/get',
dataType: "json",
data: { action: "all" }
})
.always(function() {
//something
})
.done(function(json) {
console.log("done");
})
.fail(function() {
console.log("error");
});
The mockjax properly returns the (JSON) data, but the problem is that always the done()
callback is called (and never the fail()
), regardless of mockjax status number set.
But if I intentionally set the bad proxy path, only then the fail()
is fired.
What gives?
Upvotes: 1
Views: 1029
Reputation: 3884
Until the mockjax issue is resolved, here are (some) workarounds that fire $.ajax.fail()
callback:
isTimeout: true
proxy:
pathUpvotes: 0