The problem is fixed in Mockjax v1.5.3.
jQuery doesn't fire $.ajax.fail() when Mockjax returns status:500 (or 400 or...)
-
28-06-2022 - |
Pregunta
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?
Solución
Otros consejos
Until the mockjax issue is resolved, here are (some) workarounds that fire $.ajax.fail()
callback:
isTimeout: true
- malformed
proxy:
path
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow