The order of execution of a piece of code outside of the Jquery $.ajax function _ajax Related

Source: Internet
Author: User

Today, I met a very painful problem. The asynchronous function $.ajax of jquery is called in one function, and then there is a section of jquery code outside the $.ajax function. Each time the code after the $.ajax is executed first.

Search on the internet for a long time finally found the reason. Take it and share it with everyone before you forget it.

Async:false

var flag=true; 

The Async:false representative only executes the 
$.ajax ({url: "Emailcheck.ashx", Async:false,data: {"Email": $ ("#email") after waiting for the Ajax execution to complete. Val () }). Done (function (data) { 
if (data== "Fail") 
{ 
flag=false; 
} 
); 

if (flag) 
{ 
$ ("#showInfo"). Text (""); 
return true; 
} 
else 
{ 
alert ("This mailbox already exists!"); 
$ ("#showInfo"). Text ("This mailbox already exists"); 
return false; 
} </span>

Because jquery has not been very proficient, it seems that the future will take time to learn.

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.