Description: Register a handler to be called when the first Ajax request begins. This is an Ajax Event.version added: 1.0
描述:注册一个当第一个ajax请求开始时(同时多个ajax请求的情况)执行的处理器。这个一个ajax事件。起始版本1.0
.ajaxStart( handler() )
handler()The function to be invoked.回调函数。
Whenever an Ajax request is about to be sent, jQuery checks whether there are any other outstanding Ajax requests. If none are in progress, jQuery triggers the ajaxStart event. Any and all handlers that have been registered with the .ajaxStart() method are executed at this time.
当要发送ajax请求时,jQuery检查是否有任何其他响应过程中的Ajax请求。如果没有检查到,jQuery就会触发ajaxStart事件,这时所有注册在.ajaxStart()方法上的处理器将被执行。
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').ajaxStart(function() {
$(this).text('Triggered ajaxStart 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 is sent, the log message is displayed.
当用户点击了拥有trigger class的元素并且ajax请求发送,这时log信息将会被显示。
Note: Because .ajaxStart() 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.
注意:因为.ajaxStart()是作为一个jQuery对象实例方法去执行的,所以我们可以在回调函数中使用this关键字表示当前被选择的元素。
Example:
Show a loading message whenever an Ajax request starts (and none is already active).
例子:当ajax请求开始时显示加载信息(没有一个Ajax请求是已经激活的情况下)。
$("#loading").ajaxStart(function(){
$(this).show();
});
描述:注册一个当第一个ajax请求开始时(同时多个ajax请求的情况)执行的处理器。这个一个ajax事件。起始版本1.0
.ajaxStart( handler() )
handler()The function to be invoked.回调函数。
Whenever an Ajax request is about to be sent, jQuery checks whether there are any other outstanding Ajax requests. If none are in progress, jQuery triggers the ajaxStart event. Any and all handlers that have been registered with the .ajaxStart() method are executed at this time.
当要发送ajax请求时,jQuery检查是否有任何其他响应过程中的Ajax请求。如果没有检查到,jQuery就会触发ajaxStart事件,这时所有注册在.ajaxStart()方法上的处理器将被执行。
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').ajaxStart(function() {
$(this).text('Triggered ajaxStart 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 is sent, the log message is displayed.
当用户点击了拥有trigger class的元素并且ajax请求发送,这时log信息将会被显示。
Note: Because .ajaxStart() 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.
注意:因为.ajaxStart()是作为一个jQuery对象实例方法去执行的,所以我们可以在回调函数中使用this关键字表示当前被选择的元素。
Example:
Show a loading message whenever an Ajax request starts (and none is already active).
例子:当ajax请求开始时显示加载信息(没有一个Ajax请求是已经激活的情况下)。
$("#loading").ajaxStart(function(){
$(this).show();
});