Home >Web Front-end >JS Tutorial >Briefly describe the execution sequence of jQuery ajax_jquery
The default async of Ajax in jQuery is true (asynchronous request). If you want to execute another Ajax after one Ajax is executed, you need to set 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); } }); }
Then take a look at the execution sequence of each jquery $.ajax event
The execution sequence is as follows:
1.ajaxStart (global event)
2.beforeSend
3.ajaxSend (global event)
4.success
5.ajaxSuccess (global event)
6.error
7.ajaxError (global event)
8.complete
9.ajaxComplete (global event)
10.ajaxStop (global event)