Is it possible to create and attach a callback which would get called whenever an ajax request completes regardless of whether the call was made using $.ajax
, $.post
, load
or any other function?
EDIT:
The solution given by Nakul (using ajaxSuccess global event) is almost perfect. However I have a problem when using this with the load
function. The ajaxSuccess event is raised after the request has completed but before any DOM manipulation. I would like to execute some code after the DOM has been modified. My temporary solution is to use setTimeout
and wait for a couple of milliseconds but I don't think it'd be reliable enough for me.
So another question is: how can you execute code after the DOM has been manipulated by the load
function?
EDIT 2:
I've managed to solve the second issue by using ajaxComplete event instead of ajaxSuccess.