开发者

Using jquery .load without a delay

I create div place holders in my html and store the url for fetching on the rel attribute, some of these urls are slower to load

when using the folowing code, the each loop waits for each load function to be done before moving along to the next one which make an html with 5 placeholders load pretty slow:

$("div[class=ajax_wrapper]").each(function() {
            $(this).load($(this).attr('rel'), function(content) {
                //alert(content);
            });    开发者_Go百科 
        });

How can I make the different divs load asynchronously?


You use AJAX to load the contents of each div resulting into multiple parallel asynchronous requests and until those requests complete the content cannot be shown. You may try loading their contents directly on the server on the first request and send them as part of the initial HTML. If the contents had to change you could use AJAX to refresh only the div that need to be changed.


How about this

$("div[class=ajax_wrapper]").load($(this).attr('rel'), function(content) {
            //alert(content);
        });     
});

Edit: in document.ready, of course, i.e. wrapped in:

$( function() { //code } );
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜