jQuery ajax请求 - ajaxStart() ajaxSend() 方法
ajaxStart() 只对 ajax请求的第一次触发,而 ajaxSend()方法则会对 所有ajax请求都会触发
实例:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs
/jquery/1.4.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").ajaxSend(function(){
alert("对所有 AJAX 请求都会触发");
});
$("button").click(function(){
$("div").load("http://www.w3school.com.cn/example/jquery/demo_ajax_load.txt");
$("div").load("http://www.w3school.com.cn/example/jquery/demo_ajax_load.asp");
});
});
</script>
</head>
<body>
<div id="txt"><h2>通过 AJAX 改变文本</h2></div>
<button>改变内容</button>
</body>
</html>
结果:对话框会弹出两次,但如果将ajaxSend()改成ajaxStart(),则对话框只弹出一次,同理,ajaxComplete()会对所有ajax请求都触发,而ajaxStop则只对最后一次的ajax请求进行触发。