Description: Register a handler to be called when all Ajax requests have completed. This is an Ajax Event.version added: 1.0
描述:注册一个当所有ajax请求完成时被执行的处理器。这是一个ajax事件。其实版本1.0
.ajaxStop( handler() )
handler()The function to be invoked.回调函数。
Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the ajaxStop event. Any and all handlers that have been registered with the .ajaxStop() method are executed at this time. The ajaxStop event is also triggered if the last outstanding Ajax request is cancelled by returning false within the beforeSend callback function.
当一个ajax请求完成时,jQuery会检查是否还有其他ajax请求在响应,如果没有,jQuery将触发ajaxStop事件。这时所有注册在.ajaxStop()方法上的处理器将被执行。 如果最后一个正在响应中的ajax请求被取消(在beforeSend回调函数中返回false),ajaxStop事件也会被触发。
To observe this method in action, we can set up a basic Ajax load request:
为了观察该方法的实际运行,我们可以建立一个基本的ajax加载请求:
<div class="trigger">Trigger</div>
<div class="result"></div>
<div class="log"></div>
We can attach our event handler to any element:
我们可以将事件处理器绑定到任何的元素。
$('.log').ajaxStop(function() {
$(this).text('Triggered ajaxStop handler.');
});
Now, we can make an Ajax request using any jQuery method:
现在我们可以使用任何一个jQuery Ajax方法建立一个ajax请求:
$('.trigger').click(function() {
$('.result').load('ajax/test.html');
});
When the user clicks the element with class trigger and the Ajax request completes, the log message is displayed.
当用户点击了拥有trigger class的元素并且ajax请求完成后,这时log信息将会被显示。
Because .ajaxStop() is implemented as a method of jQuery object instances, we can use the this keyword as we do here to refer to the selected elements within the callback function.
注意:因为.ajaxStop()是作为一个jQuery对象实例方法去执行的,所以我们可以在回调函数中使用this关键字表示当前被选择的元素。
Example:
Hide a loading message after all the Ajax requests have stopped.
例子:当所有ajax请求停止后隐藏加载信息。
$("#loading").ajaxStop(function(){
$(this).hide();
});
描述:注册一个当所有ajax请求完成时被执行的处理器。这是一个ajax事件。其实版本1.0
.ajaxStop( handler() )
handler()The function to be invoked.回调函数。
Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the ajaxStop event. Any and all handlers that have been registered with the .ajaxStop() method are executed at this time. The ajaxStop event is also triggered if the last outstanding Ajax request is cancelled by returning false within the beforeSend callback function.
当一个ajax请求完成时,jQuery会检查是否还有其他ajax请求在响应,如果没有,jQuery将触发ajaxStop事件。这时所有注册在.ajaxStop()方法上的处理器将被执行。 如果最后一个正在响应中的ajax请求被取消(在beforeSend回调函数中返回false),ajaxStop事件也会被触发。
To observe this method in action, we can set up a basic Ajax load request:
为了观察该方法的实际运行,我们可以建立一个基本的ajax加载请求:
<div class="trigger">Trigger</div>
<div class="result"></div>
<div class="log"></div>
We can attach our event handler to any element:
我们可以将事件处理器绑定到任何的元素。
$('.log').ajaxStop(function() {
$(this).text('Triggered ajaxStop handler.');
});
Now, we can make an Ajax request using any jQuery method:
现在我们可以使用任何一个jQuery Ajax方法建立一个ajax请求:
$('.trigger').click(function() {
$('.result').load('ajax/test.html');
});
When the user clicks the element with class trigger and the Ajax request completes, the log message is displayed.
当用户点击了拥有trigger class的元素并且ajax请求完成后,这时log信息将会被显示。
Because .ajaxStop() is implemented as a method of jQuery object instances, we can use the this keyword as we do here to refer to the selected elements within the callback function.
注意:因为.ajaxStop()是作为一个jQuery对象实例方法去执行的,所以我们可以在回调函数中使用this关键字表示当前被选择的元素。
Example:
Hide a loading message after all the Ajax requests have stopped.
例子:当所有ajax请求停止后隐藏加载信息。
$("#loading").ajaxStop(function(){
$(this).hide();
});