JS scroll to the bottom of the page automatically loads more

<HTML> <head> <Meta charset = "GB18030" /> 
    <Script type = "text / JavaScript" the src = "./ JS / jquery.js"> </ Script> 
    <Script> 
        var totalheight = 0; 
        function the loadData () { 
            totalheight = parseFloat ($ (window) .height ()) + parseFloat ($ (window) .scrollTop ());              IF ($ (Document) .height () <= totalheight) {// the scroll bar has been described of the bottom                 / * used herein Ajax load more content * /                 var container = $ ( "# container"); // loading container                 var data = {}; // query parameter                 // this page                 var currentPage = parseInt (container.find ( '#currentPage') val () ).;                // total number of pages                 var maxPage = parseInt (container.find ( ' # maxPage') val ().);
            








                // 查询日期范围
                var startDate = container.find('#startDate').val());
                var endDate = container.find('#endDate').val());
                data.currentPage = currentPage;
                data.maxPage = maxPage;
                data.startDate =startDate;
                data.endDate = endDate;
                jQuery.ajax({ 
                    type:"POST", 
                    url: "/servlet/query.do", 
                    data:data, 
                    dataType: "json", 
                    beforeSend: function(XMLHttpRequest){ 
                        $("#loading").css('display',''); 
                    }, success:function(response) { 
                        if(response.data){ 
                            for(var i=0, length = response.data.length; i<length; i++){ 
                                var html = response.data[i]; 
                                var test = $(html); 
                                container.append(test); 
                            } 
                            container.find('#currentPage').val(parseInt(currentPage)+1)); 
                            $("#loading").css('display','none'); 
                        } 
                    }, error:function(){ 
                        alert("加载失败"); 
                    } 
                }); 
            } 
        } 
        $(window).scroll( function() { 
            loadData();
        }); 
    </script> 
</head> 
<body>  
    <div id="container">
        这里显示内容
    </div>
    <div id='loading'>
        <img src="./imgs/loading.gif"/>
    </div>
</body> 
</html>

Reproduced in: https: //my.oschina.net/kt431128/blog/224711

Guess you like

Origin blog.csdn.net/weixin_34244102/article/details/91952488