简体   繁体   中英

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

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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM