The Ajax in jquery is async by default (asynchronous request), and if you want to perform another Ajax after an Ajax execution, you need to 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 look at the jquery $.ajax. Sequence of events executed
The order of execution 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)