jquery中各个事件执行顺序
jquery中各个事件执行顺序如下:
1.ajaxStart(全局事件)
2.beforeSend
3.ajaxSend(全局事件)
4.success
5.ajaxSuccess(全局事件)
6.error
7.ajaxError (全局事件)
8.complete
9.ajaxComplete(全局事件)
10.ajaxStop(全局事件)
其中,全局事件可以在ajax相关方法外引用(比如,通过该方式将ajax执行各个阶段的信息显示在页面某个地方)。
示例:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(function(){ //点击按钮,并执行ajax请求 $("#ajaxReuqestID").click(function(){ $.ajax({ url: "http://hi.baidu.com/hinew/pc.html", error:function(){ $("#ajaxStateID").text("error"); alert("error"); }, success: function(){ $("#ajaxStateID").text("success"); alert("success"); }, complete:function(){ $("#ajaxStateID").text("complete"); alert("complete"); }, beforeSend:function(){ $("#ajaxStateID").text("berforeSend"); alert("berforeSend"); } }); }); // 注意从jquery 1.8.0以后,全局函数需要绑定到document上 $(document).ajaxStart(function(){ $("#ajaxStateID").text("ajaxStart"); alert("ajaxStart"); }).ajaxSend(function(){ $("#ajaxStateID").text("ajaxSend"); alert("ajaxSend"); }).ajaxSuccess(function(){ $("#ajaxStateID").text("ajaxSuccess"); alert("ajaxSuccess"); }).ajaxError(function(){ $("#ajaxStateID").text("ajaxError"); alert("ajaxError"); }).ajaxComplete(function(){ $("#ajaxStateID").text("ajaxComplete"); alert("ajaxComplete"); }).ajaxStop(function(){ $("#ajaxStateID").text("ajaxStop"); alert("ajaxStop"); }); }) </script> </head> <body> <input type="button" value="点击触发ajax请求" id="ajaxReuqestID"/> <div id="ajaxStateID"></div> </body> </html>
相关推荐
pigsmall 2020-11-19
SXIAOYI 2020-09-16
Ladyseven 2020-07-25
whileinsist 2020-06-24
gufudhn 2020-06-12
冰蝶 2020-06-05
LinuxAndroidAI 2020-06-04
supperme 2020-05-28
yaodilu 2020-05-10
e度空间 2020-04-27
云端漂移 2020-04-09
peterwzc 2020-03-17
有心就有方向 2012-09-03
ebuild 2013-05-14
donghedonghe 2013-05-31
tdeclipse 2011-02-28
linuxprobe0 2013-04-15
linuxprobe0 2013-04-01