Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何使用ajax实现无限滚动?_Jquery_Ajax_Asp.net Ajax - Fatal编程技术网

Jquery 如何使用ajax实现无限滚动?

Jquery 如何使用ajax实现无限滚动?,jquery,ajax,asp.net-ajax,Jquery,Ajax,Asp.net Ajax,我使用ASP.NET 我想在我的页面上显示我的数据库帖子和评论。我可以用一个函数来显示它们。但我想添加无限滚动属性。当用户滚动页面时,页面应重新加载并继续。你知道我就像Facebook,Twitter 我该怎么做?这是我在页面上显示数据的代码。我在JQuery中搜索了滚动函数,但我并没有一起搜索 $(function () { var posts = jQuery.parseJSON($("#MainContent_hdnPosts").val());

我使用ASP.NET

我想在我的页面上显示我的数据库帖子和评论。我可以用一个函数来显示它们。但我想添加无限滚动属性。当用户滚动页面时,页面应重新加载并继续。你知道我就像Facebook,Twitter

我该怎么做?这是我在页面上显示数据的代码。我在JQuery中搜索了滚动函数,但我并没有一起搜索

      $(function () {
        var posts = jQuery.parseJSON($("#MainContent_hdnPosts").val());
        $("#Post").html("");
        var html = "";
        $.each(posts, function (index, a) {
            html += '<tr><td>' + a.userId + '</td></tr>';

        });
        $("#Post").append(html);
    });
使用以下代码,我为您提供了在ASP.NET后端执行的PHP示例:

装载

函数加载更多数据

在控制器上,您接收ID并选择大于当前接收ID的数据

 $(window).scroll(function () {
    if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
        var last_id = $("#ticketHistoryData a:last-child").attr('id');
        loadMoreData(last_id);
    }
});
** 
function loadMoreData(last_id) {
    $.ajax(
        {
            url: '../../controllers/support/fetch_hdata.php?last_id=' + last_id ,
            type: "get",
            beforeSend: function () {
                $('.ajax-load').show();
            }
        })
        .done(function (data) {
             $('.ajax-load').hide();
            $("#ticketHistoryData").append(data);
        })
        .fail(function (jqXHR, ajaxOptions, thrownError) {
            console.log('server not responding...');
        });
}
select * from data where id < '" . $lastId . "' ORDER BY id DESC LIMIT 10;