I have a page where I use the jquery .get()
method to load in contents and .html()
to display them on my page. During the loading process I have a div box with a preloader positioned above my page to hide the new elements popping up and instead display a gif.
Some pages take very long to load though, as there are iframes, pictures etc included in them. Now I only want the preloader div to be removed after everything has been fully loaded, which is where I can't find an answer, as there is no .html()
callback function.
I've tried .load()
, .on()
with load as an event, the .done()
function on the .get()
method but nothing seems to work as I would like to have it.
Is there any chance to find out, when the the contents of my ajax div have finished loading, so I can then remove the preloader?
Edit
This is my HTML Markup
<div class="wrapper">
<div class="ajax_cont">
<!-- The content will come in here -->
</div>
<div class="preloader"></div>
</div>
Maybe I didn't explain the problem clear enough, so here is my js code as well:
function load_ajax(linktofile) {
$(".preloader").fadeIn(200);
setTimeout(function() {
$.get("ajax/" + linktofile, function(data){}).done(function(data) {
var content = $(data).filter('#loaded_content').html();
$(".ajax_cont").html(content); //It takes a while until all pictures, which were included in content, are fully loaded in .ajax_contnt
setTimeout(function() {
$(".preloader").fadeOut(200); //I want this to be executed only when everything is fully ready
}, 150);
});
}, 200);
}
I've added a few comments to clarify, what exactly I meant.