Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deprecated jQuery callbacks- clarification?

Since jQuery 1.5 - jqXHR objects returned by $.ajax() implement the Promise interface.

The docs also state that jqXHR.done , jqXHR.fail , jqXHR.always are alternative constructs for the deprecated success / fail/ complete respectively.

Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.

ok.(known a long time ago)

But then I saw the async doc :

async : As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done() or the deprecated jqXHR.success().

The wording here are very unclear (imho) - thus , I don't understand the meaning of it.

Question :

Are there any situations which still I need to use success/error/complete ? how come ? they are deprecated !

nb , why all this mess ? they change and remove methods and replace(! eg pipe , then) like every version

like image 545
Royi Namir Avatar asked Mar 19 '14 07:03

Royi Namir


1 Answers

Conclusion:

What is deprecated is using async: false and jqXHR ($.Deferred) API at same time (The combining usage).

The success/error/complete callback options of $.ajax() are not deprecated.

The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated.

When using async AJAX request (async: true), you could use either success/error/complete callback options of $.ajax() or jqXHR.done, jqXHR.fail , jqXHR.always.

But when using synchronous AJAX requests(async: false), you should not use the deferred API(jqXHR.done, jqXHR.fail , jqXHR.always), but use success/error/complete callback options of $.ajax().

like image 80
xdazz Avatar answered Sep 28 '22 11:09

xdazz