I have a page that loads content through AJAX. Among this content are some images. I need to do some formatting to the page layout depending on the images sizes (which vary) but in order to get the sizes, I need the images to finish loading first before running the code. If it was in an ordinary page (content loading normally WITHOUT AJAX), all I have to do is use the $(window).load() function but with AJAX it doesn't trigger for some reasons. I need a workaround to this : a way to execute some code after the images loaded through AJAX finish loading.
Basically, this is what I'm trying to do
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.getElementById("results").innerHTML=ajaxRequest.responseText;
//the responseText includes images among other information to be loaded
$(window).load(function() {
...some code
});}}
but the $(window).load() never fires and I need to run the code once ALL images have finished loading so binding a load event to every image isn't really an option.
I have another question that is related and similar to the first one : the jQuery $(document).ready doesn't seem to fire either after content is loaded through AJAX. I don't need it right now but I will certainly do in the future, so any workarounds for this too ?
I would really appreciate your help and thanks a lot.
load()in API$(window).bind('load',function)would be the event you are looking for