javascript - Ajax jQuery load in 9 divs at a time -
i'm having div looks this:
<div class="all_articles third_article_module"> <!--load in content loadmore.html via ajax --> </div>
i have show me more text looks this:
<div class="showmemore"> <h2>load more articles</h2> </div>
my loadmore.html page loops through , show articles. ting want show number of articles each time (for example 9) , h2 tag appends end of div. when there's no more articles left want h2 tag hidden. js looks this:
$('.showmemore_inner h2').on("click", function(e){ e.preventdefault(); $('.third_article_module').load('loadmore.html'); }); $(document).ajaxstart(function(){ $(show_header).text('loading more articles').css('color', '#4c4c4e'); $('.showmemore .showmemore_inner h2 span').css('display', 'block'); }); $(document).ajaxcomplete(function(){ $('.showmemore').appendto('.all_articles.third_article_module'); $('.ajax_article').addclass('active'); $(show_header).text('load more articles'); });
in loadmore.html have div container , content each wrapped in div that's called .ajax_article.
you should add parameter loadmore.html tell how many articles need , start. this:
var start = 0; $('.showmemore_inner h2').on("click", function(e){ e.preventdefault(); $('.third_article_module').load('loadmore.html?articles=9&start=' + start,'',function(data) {if(!data) {$('.showmemore_inner h2').remove();}}); start = start + 9; });
this ensure each time show more clicked, next 9 articles fetched, , if no data received show more removed. of course in loadmore.html should loop articles requested parameters.
Comments
Post a Comment