Describe the execution sequence of jQuery ajax
- 2020-11-18 06:07:57
- OfStack
The default async for Ajax in jQuery is true(asynchronous request). If you want to execute one Ajax before executing another Ajax, you need to put async=false.
The code is as follows:
function TestAjax()
{
var UserName = $("#txtUserName").val();
$.ajax({
url:"AjaxCheckUserName.htm",
async:false,
success:function(data){
alert(data);
}
});
alert('Test');
$.ajax({
url:"AjaxHandler.ashx",
async:false,
data:"UserName=" + UserName,
success:function(data){
$("#divAjax").html(data);
},
error:function(msg){
alert(msg.responseText);
}
});
}
Next, take a look at the order in which jquery $.ajax executes each event
The execution sequence is as follows:
1.ajaxStart(Global Events)
2.beforeSend
3.ajaxSend(Global events)
4.success
5.ajaxSuccess(Global Events)
6.error
7.ajaxError (Global Events)
8.complete
9.ajaxComplete(Global events)
10.ajaxStop(Global events)