jQuery AJAX:.done(), .fail(), .always(), and .then()

Versus

.succes(), .error()

Many functions!

Can someone explain a bit more? The .success and .error is understand what do. The .done is not really is do .always something? .fail and .done seems .error and .success or what the difference? And what about .then? And .complete is seems if executed both .error and .success?

Thanks!

.success() is deprecated, use the replacement .done()
.error() is deprecated, use the replacement .fail()
.complete() is deprecated, use the replacement .always()

2 Likes

Ah now this way half goes off! And you know any about .then?

jqXHR (which is the object that the $.ajax function returns) is promise compliant. then takes a promise, allows you to do something to the value it contains, and returns a new promise

someAjaxThing
  .then(data => /* do something to the data */)
  .then(data => /* do something else to the data*/)
1 Like