Home > Article > Web Front-end > The execution sequence of a piece of code outside the Jquery $.ajax function
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>
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!