user3391747 user3391747 - 6 months ago 30
Ajax Question

jquery fail not firing

I am quite new to jquery/ajax, but I am trying to use

done
instead of
success
and
fail
instead of
error
. It does what I want for
done
, but
fail
does not seem to be firing? The code below works, but if I change
error
to
fail
it does not set value of callback to
Error
.

done: function() {
callback("Success");
},
error: function() {
callback("Error");
}


Anyone know what might be wrong?

Thanks!

Answer

Fail is part of the Promise interface so you need to do it like this

$.ajax({})
   .done( function() {} )
   .fail( function() {} )
   .always( function() {} );