Q:

Is $.ajax's error option the same as .fail()?

Can anyone tell me if there is any difference between these two jquery calls?
$.get("/foo", function (data, textStatus, jqXHR) {
    doThingA()
}).fail(function () {
    doThingB()
});

vs
$.ajax({
    url: "/foo",
    success: function (data, textStatus, jqXHR) {
        doThingA()
    },
    error: function () {
        doThingB()
    }
});

I'm refactoring some code and just wondering if these two are exactly the same.  I think if there is a difference it's most likely to be between fail() and the error option.  Grateful for any advice, thanks.

A:

Yes, they are the same.
http://api.jquery.com/jquery.ajax/#entry-longdesc

jqXHR.done(function( data, textStatus, jqXHR ) {});
  An alternative construct to the success callback option, [...]
jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
  An alternative construct to the error callback option, [...]

The AJAX methods (.ajax(), .get(), etc.) return promises, which have these methods on them.
An example:
var promise = $.get("/api/user/" + userid);
promise.done(function () { /* ... */ });
promise.fail(function () { /* ... */ });
promise.always(function () { /* ... */ });

You can also chain the method calls.

