Home > Web Front-end > JS Tutorial > body text

The execution sequence of a piece of code outside the Jquery $.ajax function

亚连
Release: 2018-05-25 15:58:16
Original
1594 people have browsed it

The JQuery asynchronous function $.ajax is called, and then there is a piece of Jquery code outside the $.ajax function. Every time, the code after $.ajax is executed first

I encountered a very painful problem today. The JQuery asynchronous function $.ajax is called in a function, and then there is a piece of Jquery code outside the $.ajax function. Every time, the code after $.ajax is executed first.

After searching online for a long time, I finally found the reason. Take it and share it with everyone so that you don’t forget it later.

async:false

var flag=true; 

//async:false代表只有在等待ajax执行完毕后才执行 
$.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("该邮箱已存在!"); 
$("#showInfo").text("该邮箱已存在"); 
return false; 
}</span>
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Convert form elements to JSON by constructing AJAX parameters

Discuss some minor issues in Ajax

ajax callback opens a new form to prevent browser interception Effective method_AJAX related


The above is the detailed content of The execution sequence of a piece of code outside the Jquery $.ajax function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!