$.when (). Then ()

Source: Internet
Author: User

Executes a function when two AJAX requests are successful myFuncIf any of the errors are executed myFailure

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

.then(myFunc, myFailure);

Jquery.when (deferreds)

Parameter deferreds, one or more delay objects or JS objects, we initially think of it as one or more asynchronous requests.

For example:

[JavaScript]View Plaincopyprint?
    1. $.when ($.ajax ("page1.php"), $.ajax ("page2.php"))
$.when ($.ajax ("page1.php"), $.ajax ("page2.php"))

the When () function is often used in conjunction with the Done () function, fail () function, then () function: Done (Function func)-Execute function callback when processing in Deferreds is complete fail (Function func)-Whena function callback is executed when there is a processing failure in the Deferredsthen (function func1,function func2)-combines the done and fail functions, when both execute func1 successfully, when there is a failure to execute FUNC2

Example:

[JavaScript]View Plaincopyprint?
  1. var  Whenresult = $.when ($.ajax ("page1.php"), $.ajax ("page2.php"));
  2. Whenresult.done (function(A1,A2) {
  3. //function content slightly   
  4. //A1 and A2 parameters are related JQXHR objects of two AJAX requests in the When function   
  5. });
  6. Whenresult.fail (function() {
  7. //function content slightly   
  8. })
  9. Whenresult.then (Successfunc,failurefunc);
var whenresult = $.when ($.ajax ("page1.php"), $.ajax ("page2.php")), Whenresult.done (function (A1,A2) {//function content slightly// The A1 and A2 parameters are the related JQXHR objects of two AJAX requests in the When function}), Whenresult.fail (function () {//function contents}) Whenresult.then (Successfunc, FAILUREFUNC);

$.when (). Then ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.