如何在向下滚动javascript函数时调用loadmore函数(仅一次)?

时间:2015-06-14 14:02:39

标签: javascript ajax api scroll

我正在使用以下代码在用户向下滚动并到达页面底部时触发我的onloadmore功能。但是我注意到很多时候函数在向下滚动时被多次调用!任何人都可以告诉我为什么对于相同的数据集,loadmore函数会被调用一次!是互联网连接问题?我只想让loadmore只调用一次!

     <script>
var nextTagId = null;
       function callLoadMore() {

               $.ajax({
                type: "GET",

                dataType: "jsonp",

                cache: false,

                url: "http://api.sometime.com/api.php?count=100" + ( nextTagId ? "&next_id=" + nextTagId : ""),


        success: function(data) {

         for (var i = 0; i < 100; i++) {

                    document.myform.outputtext.value = document.myform.outputtext.value+data.data[i].pics.standard.path+'\n' ;

                    }
                }

            });

        }
    </script>
<script>
        $(function() {
            $(window).bind("scroll", function (){ 
                console.log("SCROLL : " + $(window).scrollTop() 
                    + " - " + $(window).innerHeight() 
                    + " - " + document.body.clientHeight);
                if ($(window).scrollTop() + document.body.clientHeight >= $(window).innerHeight()) {
                            //alert('Bottom!');

                               callLoadMore();

                }
            });
        });
</script>

0 个答案:

没有答案