Matthew
Matthew

Reputation: 827

Will the .done method still be supported for jqXHR objects in jQuery 3.x?

I have noticed throughout my JavaScript code that AJAX requests are often performed using the following jQuery 2.x pattern:

$.ajax({
     ...
})
.done(function (data) {
     ...
});

where the code found within the done method is to be executed after the response has been received.

After reading the beta release notes for jQuery 3.x (https://blog.jquery.com/2016/01/14/jquery-3-0-beta-released/), I noticed the following statement:

Removed special-case Deferred methods in jQuery.ajax

jqXHR object is a Promise, but also has extra methods like .abort() so that you can stop a request after it has been made.

As users increasingly embrace the Promise pattern for asynchronous work like AJAX, the idea of having special cases for the Promise returned by jQuery.ajax is an increasingly bad idea.

success, error, complete, done, fail, always

Note that this does not have any impact at all on the callbacks of the same name, which continue to exist and are not deprecated. This only affects the Promise methods!

If I'm reading this correctly, it seems to indicate that my method for executing JavaScript code after the response has been returned will no longer be supported. Is that the case, or am I missing something? Also, am I correct in understanding that the success and error callback functions are now the preferred method for performing such a task?

Any clarification here would be greatly appreciated!

Upvotes: 1

Views: 213

Answers (1)

Bergi
Bergi

Reputation: 665276

Taking a look at the beta code, I can confirm that the

  • done
  • fail
  • always
  • progress
  • state
  • pipe

methods continue to be supported, in addition to the new then and catch methods.

On jqXHR objects (which are also promises), the methods success, error, complete (which were deprecated as of 1.8) have been removed.

Upvotes: 2

Related Questions