jquery ajax 中各个事件执行顺序如下:

1.ajaxStart(全局事件)

2.beforeSend

3.ajaxSend(全局事件)

4.success

5.ajaxSuccess(全局事件)

6.error

7.ajaxError (全局事件)

8.complete

9.ajaxComplete(全局事件)

10.ajaxStop(全局事件)

下面看个例子:

 $("#ACCOUNT_TYPE").bind('click', function() {
//alert( $(this).val());
var msg="";
if($(this).val()=="B134002")//托管
{
//msg="托管";
msg="ACCOUNT_TYPE_COM_T";
}
else if($(this).val()=="B134001")//存管
{
//msg="存管";
msg="ACCOUNT_TYPE_COM_C";
}
else if($(this).val()=="-")//存管和托管all
{
//msg="存管和托管";
msg="ACCOUNT_TYPE_COM_ALL";
}
else
{
alert("参数错误!");
return;
} $("#ACCOUNT_TYPE_COMDiv_son").children().remove();//先清除所有子元素
$.ajax({
type:"post",
url:"${ctx}/Rule/Combination/getdict",
data:{type:msg},
dataType:"json",
success:function(json)
{
//$(object).children(selector).remove(); // 删除object元素下满足selector选择器的子元素,不填写则默认删除所有子元素 for(var i=0;i<json.length;i++)
{
var checkBox=document.createElement("input");
//checkBox.setAttribute("type","checkbox");
checkBox.setAttribute("type","radio");
checkBox.setAttribute("id", json[i].value);
checkBox.setAttribute("value", json[i].value);
checkBox.setAttribute("name", "ACCOUNT_TYPE_COM");
checkBox.setAttribute("checked", true);
//checkBox.setAttribute("readonly", true);//
var li=document.createElement("span"); li.style.display = "block";
li.style.width = 23+"%";
li.style.float = "left"; li.appendChild(checkBox);
li.appendChild(document.createTextNode(json[i].label)); $("#ACCOUNT_TYPE_COMDiv_son").append(li); }
}
,
beforeSend:function(mes)
{
alert("beforeSend");
},
complete:function()
{
alert("complete");
}
});
});

运行这段代码,会先弹出 beforeSend  提示,然后加载success 方法里面的代码,最后弹出 complete  提示,这说明这段代码的几个方法的执行先后顺序是符合上面总结的顺序的!

全局事件的例子:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").ajaxStart(function(){ $(this).html("<img src='/i/demo_wait.gif' />");
alert("1.最先的全局方法");
});
$("button").click(function(){
$("div").load("/example/jquery/demo_ajax_load.asp");
}); $("div").ajaxSend(function()
{
alert("2.发送前");
});
$("div").ajaxSuccess(function()
{
alert("3.成功后");
});
$("div").ajaxComplete(function()
{
alert("4.ajaxComplete");
});
$("div").ajaxStop(function()
{
alert("5.ajaxStop");
}); });
</script>
</head> <body> <div id="txt"><h2>通过 AJAX 改变文本</h2></div>
<button>改变内容</button> </body>
</html>

每次点击 "改变内容" 的这个按钮,都会先加载一次demo_wait.gif 这个图片,然后执行 ajaxSend,然后执行 ajaxSuccess,然后执行ajaxComplete,然后执行 ajaxStop ,这个执行顺序也是符合上面总结的顺序的!

 

jquery ajax 中各个事件执行顺序的更多相关文章

  1. jquery ajax中各个事件执行顺序如下

    $(function(){ setTimeout(function(){ $.ajax({ url:'/php/selectStudent.php', }); },0); $(document).aj ...

  2. jquery中各个事件执行顺序如下:

    jquery中各个事件执行顺序如下: 1.ajaxStart(全局事件) 2.beforeSend 3.ajaxSend(全局事件) 4.success 5.ajaxSuccess(全局事件) 6.e ...

  3. 关于AJAX中函数的执行顺序

    考察w3school上的一个实际的例子[1]: <html> <head> <script type="text/javascript"> fu ...

  4. Global中的事件执行顺序

    The Global.asax file, sometimes called the ASP.NET application file, provides a way to respond to ap ...

  5. jquery ajax中事件的执行顺序

    jquery中各个事件执行顺序如下: 1.ajaxStart(全局事件) 2.beforeSend 3.ajaxSend(全局事件) 4.success 5.ajaxSuccess(全局事件) 6.e ...

  6. jquery ajax 事件执行顺序

    jquery中各个事件执行顺序如下: 1.ajaxStart(全局事件) 2.beforeSend 3.ajaxSend(全局事件) 4.success 5.ajaxSuccess(全局事件) 6.e ...

  7. jquery ajax中success与complete的执行顺序

    jquery ajax中success与complete的执行顺序 jquery中各个事件执行顺序如下: 1.ajaxStart(全局事件) 2.beforeSend 3.ajaxSend(全局事件) ...

  8. jquery ajax中success与complete的执行顺序 (转)

    http://blog.sina.com.cn/s/blog_4adc4b090101dhnh.html https://q.cnblogs.com/q/21810/ **************** ...

  9. jquery ajax事件执行顺序

    jquery中各个事件执行顺序如下: 1.ajaxStart(全局事件) 2.beforeSend 3.ajaxSend(全局事件) 4.success 5.ajaxSuccess(全局事件) 6.e ...

随机推荐

  1. io.UnsupportedOperation: not readable

    两处错误一.你是用open打开一个文件,此时调用的是w写入模式,下面使用read是没有权限的,你得使用w+读写模式二.使用write写入一个字符s,但是此时并没有真正的写入,而是还存在与内存中.此时执 ...

  2. RHEL6.2 ORACLE11G

    今天翻文件看到这个系统的安装截图才发现自己没写,补上. 惯例还是用到的所有参数均位于文末附录 启动虚拟机进入系统安装 选择跳过硬盘检测 选择语言 选择基本存储设备 设定主机名 设定口令 选择使用所有空 ...

  3. linux 源码安装 mono

    $ yum install bison gettext glib2 freetype fontconfig libpng libpng-devel libX11 libX11-devel glib2- ...

  4. JMeter之http接口测试

    能做哪些类型性能测试 接口 文件传输(ftp) 数据库 支持自定义java组件开发 安装 http://jmeter.apache.org/ 进入上面的链接 选择合适版本下载 启动 使用 Jmeter ...

  5. Innodb semi-consistent 简介

    A type of read operation used for UPDATE statements, that is a combination of read committed and con ...

  6. Ubuntu上Xilinx ARM交叉编译器安装

    1,Windows中下载交叉编译器 2,在ubuntu中创建zedboard目录,并将交叉编译器复制进来 3,将该交叉编译器设置成可执行程序 chmod  a+x  xilinx-2011.09-50 ...

  7. laravel出现No hint path defined for [sudosu]的解决方法

    今天ytkah在部署laravel项目时出现了No hint path defined for [sudosu]的问题,大概意思是没有定义sudosu的提示路径,那我们找一下配置文件有没相关设置,看到 ...

  8. 下拉菜单被表单、图片、FLASH挡住的解决办法

    设置Flash的参数: <param name="wmode" value="opaque"> <object classid="c ...

  9. protocol error, got 'n' as reply type byte + redis如何后台启动

    其它机子的PHP访问redis爆“protocol error, got 'n' as reply type byte ”错误 解决办法: 在redis配置文件redis.conf中注释掉bind配置 ...

  10. internal table operation

    1: the basic operation *&---------------------------------------------------------------------* ...