Home >Web Front-end >JS Tutorial >Briefly describe the execution sequence of jQuery ajax_jquery

Briefly describe the execution sequence of jQuery ajax_jquery

WBOY
WBOYOriginal
2016-05-16 15:21:401621browse

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)

Statement:
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