繁体   English   中英

无限滚动并重新加载附加数据

[英]infinite scrolling and reloading the appended data

我有一个网页,其中可以无限滚动,并且效果很好,但是当从第二页(例如scroling.php )无限滚动到第一页(例如主页)的无限滚动后附加的数据重新加载时,它就会消失。 我的意思是没有显示。

花了几个小时后,我才知道这是因为当我尝试重新加载任何附加的div ,第二页( scrolling.php )中变量(请求的页)的值消失了。

我认为我的代码会更清楚:

$(document).ready(function() {
    var page   = 1;
    var height = $("#forheight").height();
    $(window).scroll(function() {
        if ($(window).scrollTop() + height >= $("#forscrilling").height()-10) {
            document.getElementById('infiscroll').style.display = 'block';
            page++;
            var data = {
                requested_page: page,
                listoffrndsinimplode: "<?php echo $listoffrndsinimplode; ?>"
            };
            var actual_count = "<?php echo $noofposts; ?>";
            if ((page-1)*13 >= actual_count) {
                document.getElementById('infiscroll').style.display='none';
            } else {
                $.ajax({
                    type: "POST",
                    url: "scrolling.php",
                    data:data,
                    success: function(res) {
                        $("#loadinto").append(res);
                        document.getElementById('infiscroll').style.display='none';
                    }
                });
            }
        }
    });
});

这是在第一页上进行无限滚动,下面的代码在第二页上:

<?php
session_start();                            
include_once('conn.php');
$name = $_SESSION['name'];
$id = $_SESSION['id'];
$email = $_SESSION['email'];
include_once('time.php');
$requested_page = $_POST['requested_page'];
$set_limit = (($requested_page - 1) * 13).",13";
$listoffrndsinimplode = $_POST['listoffrndsinimplode'];
$slashes = array("\'");
$friendswithoutslashes = str_replace($slashes, "'", "$listoffrndsinimplode");
$detailsoffrienda = mysql_query("
    select * from fk_views where (
        session_id IN ($friendswithoutslashes) or
        onprf_of IN ($friendswithoutslashes)) and
        (views !='' or uploadpic !='')
    order by id desc
    limit $set_limit
");
?>

这是我用于通过AJAX重新加载div的代码,该代码位于第一页:

function hits(obj) {
    var currentrateform = $(obj);
    var id = $(obj).attr("id"); //hitsform....
    $.ajax({
        type: 'POST',
        url: 'rating-manager.php', 
        data: currentrateform.serialize(),
        success: function(){
            $("#rate"+id).load("home.php #rate"+id);
        }
    });
    return false;
}

每个div都有一个唯一的ID,例如rate +唯一的注释ID,因此该ID看起来像rate1,rate2,rate3

我认为,当所请求页面的值从第二个页面移开时,则不存在注释的ID,因此它会淡出,因为该页面没有具有该ID的任何div

我只想问一下如何在第二页上存储请求的页面的值。 我无法将其存储到会话或cookie中,因为请求的页面可以是2,3,4,5,6,7可以-而且我有很多这样的页面。

您使用的是最新版本吗?

https://github.com/paulirish/infinite-scroll

我认为有一个新的选择:

appendCallback:true

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM