The execution sequence of code outside the Jquery $. ajax Function

Source: Internet
Author: User

Today I encountered a very painful problem. A JQuery asynchronous function $. ajax is called in a function, and a Jquery code is generated after the $. ajax function is added. Every time, code after $. ajax is executed first.

I searched the internet for a long time and finally found the cause. Share it with you so that you do not forget it later.

Async: false

Var flag = true; // async: false indicates that the code is executed only after ajax is executed. ajax ({url: "EmailCheck. ashx ", async: false, data: {" email ": $ (" # email "). val ()}}). done (function (data) {if (data = "Fail") {flag = false ;}}); if (flag) {$ ("# showInfo "). text (""); return true;} else {alert ("this email already exists! "); $ (" # ShowInfo "). text (" this email already exists "); return false ;}</span>

Because I have never been very familiar with Jquery, it seems that I have to spend some time learning it.

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.