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?

¿Fue útil?

Solución

The problem is fixed in Mockjax v1.5.3.

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
scroll top