Dee
Dee

Reputation: 3255

ajax success only after images of my html request are load?

Any advice how i can do it via jQ? I would like to success only when all images too are ready.. thnks

 $.ajax(
    {
        url: myUrl,
        type: 'post',
        data: postData,
        success: function (resp)
        {
            $('#content').html($('#content', resp).html());
        }
    });

thnks

Upvotes: 0

Views: 885

Answers (1)

Mark Eirich
Mark Eirich

Reputation: 10114

For this to work, you will need the special image load event plug-in. Otherwise, the event will not fire if the image is already in the browser's cache.

Then put this code inside your success handler:

var images = jQuery('#content img');
var imgcount = images.length;
images.load(function() {
    imgcount--;
    if (imgcount < 1) alert('All images are loaded.');
});

Please take the time to mark answers to your questions as Accepted, by clicking the checkmark next to the one you think is best. Thanks. :-)

Upvotes: 1

Related Questions