使用jQuery和AJAX在页面滚动上加载内容

时间:2017-10-06 13:24:31

标签: javascript jquery ajax

我尝试在使用jQuery和Ajax滚动时加载内容 我有这个代码的问题。 当我滚动并进行ajax调用时,var row_tracks不会递增,如果我对ajax请求发表评论,那么她会增加......

        WebService.WebService1 service = new WebService.WebService1();
        service.GetMessageAsync();
        service.GetMessageCompleted += Service_GetMessageCompleted;


    }

    private void Service_GetMessageCompleted(object sender, WebService.GetMessageCompletedEventArgs e)
    {
        lbl1.Text = e.Result.ToString;

    }
$(window).scroll(function(){
        var position = $(window).scrollTop(), bottom = $(document).height() - $(window).height();

        if (position == bottom) {
            var row_tracks = $('#row_tracks').html(), allcount = $('#count_tracks').html(), rowperpage = 10;
            row_tracks = parseInt(row_tracks) + rowperpage;

            console.log(row_tracks);

            if ($(".list-songs")[0] && row_tracks <= allcount) {
                $('#row_tracks').html(row_tracks);

                $.ajax({
                    url: 'ajax.php',
                    type: 'post',
                    data: {row_tracks: row_tracks},
                    success: function(response){
                        $('.list-songs').append(response);
                    }
                });
            }
        }
    });

当我发出ajax请求时, row_tracks 不会增加... enter image description here

如果我评论ajax调用,那么它会增加......

enter image description here

感谢您的帮助。

0 个答案:

没有答案