Ajax Async Async

Source: Internet
Author: User

Async defaults to True, which is asynchronous, that is, when Ajax sends a request, in the process of waiting for the server to return, the foreground will continue executing the script behind the AJAX block until the server side returns the correct result to execute the success. That is to say that this time the execution is two threads, the AJAX block makes the request after a thread and the AJAX block behind the script (another thread) example:

$.ajax ({   
           type: "POST",  
           URL: "Venue.aspx?act=init",  
           dataType: "html",  
           success:function (Result) {   //function1 ()  
              F1 ();  
              F2 ();  
           }  
            Failure:function (Result) {   
               alert (' Failed ');   
           },  
   }  
  function2 ();

In the example above, when the Ajax block makes a request, he will stay function1 (), waiting for the server side to return, but at the same time (during this wait), the foreground will go to execute function2 (), that is, at this time two threads appear, For the moment we say Function1 () and function2 ().

When the ASYCN is set to False, then the AJAX request is synchronized, that is, when the AJAX block makes the request, he will wait in the function1 () this place, not to execute function2 (), until the function1 () part of the execution is complete.

           Note: Method F1 () in success, F2 () general (i.e. F1 (), F2 () Excluding Ajax blocks) does not execute asynchronously, meaning that the execution of F2 is premised on F1 ().

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.