开发者

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());
        }
    });开发者_Go百科

thnks


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. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜