Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use jQuery.when ()

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use jQuery.when ()". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn how to use jQuery.when ().

In this case, multiple delay objects are passed to the jQuery.when, and the method returns a new "host" delay object that tracks all the states that have been aggregated through the Deferreds. When all deferred objects are accepted (resolve), this method will accept its master deferred objects. When one of the deferred objects is rejected (rejected), the method rejects its master deferred object. If the master deferred object is accepted (resolved), then the resolved value of all deferred objects is passed, and these deferred objects refer to the parameters passed to the jQuery.when. For example, when the delay object is a jQuery.ajax () request, then the incoming resolved parameter is the jqXHR object used for the request, and the order in which they are passed is the order in the parameter list.

In the case of multiple delays, if the delay one is rejected, the jQuery.when triggers an immediate call to the failCallbacks of the master delay object. Please note that in the above cases, some delay objects are still inadmissible (unresolved). So, in this case, if you need to perform some additional processing, such as canceling all outstanding ajax requests, you can keep references to jqXHR objects in the closure and check or cancel them in failCallback.

Example:

Example: the last two functions that execute the Ajax request are successful. See jQuery.ajax () for a complete description of the AJAX request for a successful and erroneous case.

When ($.ajax ("/ page1.php"), $.ajax ("/ page2.php")) .done (function (A1, a2) {

/ * A1 and a2 are arguments resolved for the

Page1 and page2 ajax requests, respectively * /

Var jqXHR = A1 [2]; / * arguments are ["success", statusText, jqXHR] * /

If (/ Whip It/.test (jqXHR.responseText)) {

Alert ("First page has' Whip It' somewhere.")

}

})

Example: execute the function myFunc when two Ajax requests are successful, if either or myFailure has an error.

When ($.ajax ("/ page1.php"), $.ajax ("/ page2.php"))

.then (myFunc, myFailure)

At this point, I believe you have a deeper understanding of "how to use jQuery.when ()". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report