On the function of async parameters in Ajax asynchronous request in jquery _jquery

Source: Internet
Author: User

Do not know the role of this parameter before, the Internet to find the predecessor of the blog, in this collection to their own blog, hoping to help more friends:

Test.html

<a href= "javascript:void (0)" onmouseover= "Testasync ()" >

Asy.js

function testasync{
 
  var temp;
  $.ajax ({
    async:false,
    type: "Get",
    URL: ' tet.php ',
    complete:function (msg) {
      alert (' Complete ') ;
    },
    success:function (data) {
      alert (' success ');
      Temp=data;
    }
  });
  Alert (temp+ ' End  ');
}

tet.php

<?php

  echo "Here is HTML code";
  Sleep (5);

? >

Async:false, (default is True);

As above: False for synchronization, the AJAX request in this Testasync () method locks the entire browser to death,

You can perform other actions only after tet.php execution has finished.

When Async:true, the AJAX request is asynchronous. But one of the problems: the AJAX request in Testasync () and its subsequent operations are performed asynchronously, so that when the tet.php is not finished, the operation behind the AJAX request may have been performed.

such as: alert (temp+ ' end ');

However, the temp data is only assigned after the AJAX request success, and the output is empty.

This article on jquery in the Ajax asynchronous request async parameters of the role is to share all the content of the small, hope to give you a reference, but also hope that we support the cloud habitat community.

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.