.ajaxSend()
S2C Home « Ajax « .ajaxSend()
Ajax global send handler.
Description
The .ajaxSend()
Ajax method, allows us to register an Ajax Event handler to be called before Ajax requests are sent.
- The
.ajaxSend()
method callbacks are executed via theajaxSend
event which is triggered every time an Ajax request is about to be sent. For finer grained control of callback execution when the.ajaxSend()
Ajax method is fired, interrogate theevent
andjqXHR
objects or theajaxSettings
parameters passed to the method.
Syntax
Signature | Description |
---|---|
.ajaxSend( handler(event, jqXHR, ajaxSettings) ) | Register an Ajax Event handler to be called before Ajax requests are sent. |
Parameters
Parameter | Description | Type |
---|---|---|
handler(event, jqXHR, ajaxSettings)) | The function to be called.
|
Function |
Return
A jQuery
object.
.ajaxSend( handler(event, jqXHR, ajaxSettings) )
ExampleTop
Register an Ajax Event handler to be called before Ajax requests are sent.
In the example below when we press the button the first time, we use the .ajaxSend()
method to set up a global event handler to be run for each Ajax request. The handler is fired every time an Ajax request is about to be sent. In this case the handler outputs a message giving some information about the request to be sent.
$(function(){
$('#btn3').one('click', function(){
// Register global event handler and attach to 'div3' element
$('#div3').ajaxSend(function(event, jqXHR, ajaxSettings) {
$(this).append('Triggered the ajaxSend() global event handler for url: '
+ ajaxSettings.url + '.<br><br>');
});
$.ajax( "../js/get3.js", {
dataType: "script",
success: function() {
$('#div3').append('The request was a success! <br>');
}
});
$.ajax( "../js/get33.js", {
dataType: "script",
success: function() {
$('#div3').append('The request was a success! <br>');
}
});
$.get( "../js/get5.js" );
$.post( "../js/post3.js" );
});
});
div3. Some initial text.
Related Tutorials
jQuery Advanced Tutorials - Lesson 11 - Ajax Global Event Handlers