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 } );
精彩评论