在滚动时在Ajax自动加载上反复加载相同的内容

时间:2013-10-24 20:23:09

标签: javascript jquery ajax

我使用来自互联网的脚本命名" jqueryscrollpagination"因为我的页面太长,所以当用户滚动到底部时,从在线自动加载内容。 实时链接 - http://www.arif-khan.net/project/chuck/jobOpening.html

我的问题是它再次显示相同的内容&滚动到底部后再次。我该如何解决?

Javascript代码 -

    <script type="text/javascript">
    $(function(){
$('#content').scrollPagination({
    'contentPage': 'more_content.html', // the url you are fetching the results
    'contentData': {}, // these are the variables you can pass to the request, for example: children().size() to know which page you are
    'scrollTarget': $(window), // who gonna scroll? in this example, the full window
    'heightOffset': 10, // it gonna request when scroll is 10 pixels before the page ends
    'beforeLoad': function(){ // before load function, you can display a preloader div
        $('#loading').fadeIn(); 
    },
    'afterLoad': function(elementsLoaded){ // after loading content, you can use this function to animate your new elements
         $('#loading').fadeOut();
         var i = 0;
         $(elementsLoaded).fadeInWithDelay();
         if ($('#content').children().size() > 100){ // if more than 100 results already loaded, then stop pagination (only for testing)
            $('#nomoreresults').fadeIn();
            $('#content').stopScrollPagination();
         }
    }
});

// code for fade in element by element
$.fn.fadeInWithDelay = function(){
    var delay = 0;
    return this.each(function(){
        $(this).delay(delay).animate({opacity:1}, 200);
        delay += 100;
    });
};

 });
 </script>

&安培;它还使用另一个脚本文件。点击此处 - http://www.arif-khan.net/project/chuck/scripts/scrollpagination.js

1 个答案:

答案 0 :(得分:0)

只是一个猜测,但如果每次都没有更改网址,那么除非服务器正在发送无缓存标头,否则您将最终得到内容的缓存副本,一遍又一遍地导致相同的数据。