.ajaxSuccess()
JQ Home <<
Ajax <<
.ajaxSuccess()
Ajax global success handler.
Description
The .ajaxSuccess()
Ajax method, allows us to register an Ajax Event handler to be called whenever an Ajax request completes successfully.
- The
.ajaxSuccess()
method callbacks are executed via theajaxComplete
event which is triggered every time an Ajax request completes. For finer grained control of callback execution when the.ajaxSuccess()
Ajax method is fired, interrogate theevent
andjqXHR
objects or theajaxSettings
parameters passed to the method.
Syntax
Signature | Description |
---|---|
.ajaxSuccess( handler( event, jqXHR, ajaxSettings) ) | Register an Ajax Event handler to be called whenever an Ajax request completes successfully. |
Parameters
Parameter | Description | Type |
---|---|---|
handler(event, jqXHR, ajaxSettings) | The function to be called.
|
Function |
Return
A jQuery
object.
.ajaxSuccess(handler( event, jqXHR, ajaxSettings))
Example Ajax << Top
Register an Ajax Event handler to be called whenever an Ajax request completes successfully.
As of jQuery 1.8, the .ajaxSuccess()
method should only be attached to document
.
In the example below when we press the button the first time, we use the .ajaxSuccess()
method to set up a global event handler to be run for each Ajax request. The handler is fired on successful
completion of a request and we output a message giving some information about the request.
$(function(){
$('#btn6').one('click', function(){
// Register global event handler and attach to 'div6' element
$(document).ajaxSuccess(function(event, jqXHR, ajaxSettings) {
$('#div6').append('Triggered the ajaxSuccess() global event handler for url: '
+ ajaxSettings.url + '. Status: ' + jqXHR.status + '. Status text: '
+ jqXHR.statusText + '.<br><br>');
});
$.getScript( "../../../js/get9.js" );
$.post( "../../../js/post6.js" );
});
});
div6. Some initial text.
Related Tutorials
jQuery Advanced Tutorials - Lesson 11 - Ajax Global Event Handlers