我有一个网页,我有无限的滚动,它的效果很好,但是当数据从第二页(比如scroling.php
)无限滚动到第一页(比如说home页面)重新加载它只是消失。我的意思是它没有显示。无限滚动和重新加载附加数据
花了几个小时我才知道,这是因为当我尝试重新加载任何附加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
。
我认为当请求页面的值离开第二页面时,不存在该评论的标识,所以它只是消失,因为该页面没有任何div
与该标识。
我只想问我如何在第二页上存储请求页面的值。我无法将它存储到会话或cookie中,因为请求的页面可能是2,3,4,5,6,7
- 任何事情 - 而且我有许多这样的页面。
appendCallback:真它做什么? – user3159415