i'm having a ajax request on the page.
is their any way to find when a ajax is requested on the page.
in jquery or javascript to find or initiate a function whn ajax request is called in a page.
i'm having a ajax request on the page.
is their any way to find when a ajax is requested on the page.
in jquery or javascript to find or initiate a function whn ajax request is called in a page.
See ajaxStart
and ajax events. Example:
$("#loading").bind("ajaxSend", function(){
$(this).show();
}).bind("ajaxComplete", function(){
$(this).hide();
});
You can bind a function to a JQuery object to be completed when any AJAX call completes.
$('#status').ajaxComplete(function(event, request, settings) {
// Do stuff here...
});
See the documentation.
If you want to set a complete function for a single AJAX call, use the low-level $.ajax()
function and setting a function for the complete
attribute.
$.ajax({
// ...
complete: function(request, settings) {
// Do stuff here...
},
// ...
});
Note: the documentation seems to contradict itself in specifying the number of arguments to the complete()
function. It may take some fiddling.