I am currently skinning an application where I have no access to the markup or scripts apart from one CSS file and on JS file so I can add my own styles and functions. Not an ideal set-up I know but believe me it’s not my choice. Oh and all the content on this site is generated via AJAX requests, nice.
Anyway, the problem is that I have a lot of Javascript that needs to run on $(document).ready(); but as the page never really reloads (due to the AJAX), none of the code gets executed.
Is there a way I can set all the functions in $(document).ready(); to run everytime the AJAX call has been completed?
I’ve included the built in AJAX call (that I cannot edit) below.
$.ajax({
type: "POST",
dataType: "html",
url: url1,
data: pars,
success: function(data)
{
$('#thisContent').html(data);
loadMenu(urlToLoad);
}
});
Yes, you can add a handler for
.ajaxComplete(). It is called after every ajax call is finished (either successfully or with error).Further reading: Ajax Events