我有一个代码,当我向下滚动页面时,它会从数据库中加载更多内容,但我的问题是当我滚动得太快时,从数据库加载的内容会重复,如果我使用此代码并且结果就是这样,这对我的用户来说会很麻烦,
这是代码:
<?php
include('../connection.php');
$action = @$_POST['action'];
$boxid = @$_POST['boxid'];
if($action <> "get")
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<link rel="stylesheet" href="scroll.css" type="text/css" />
<script type="text/javascript" src="../js/jquery-1.2.6.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){
function last_msg_funtion()
{
var boxid=$(".message_box:last").attr("id");
var action = "get";
$('div#last_msg_loader').html('<img src="bigLoader.gif">');
$.post("loader.php", { boxid: boxid, action: action }, function(data){
if (data != "") {
$(".message_box:last").after(data);
}
$('div#last_msg_loader').empty();
});
};
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
last_msg_funtion();
}
});
});
</script>
</head>
<body>
<div align="center">
<?php
$sql=mysql_query("SELECT * FROM announcements ORDER BY announce_id DESC LIMIT 10");
while($row=mysql_fetch_array($sql))
{
$msgID= $row['announce_id'];
$msg= $row['content'];
$posted= $row['postedby'];
?>
<div id="<?php echo $msgID; ?>" align="left" class="message_box" >
<span class="number"><?php echo $posted; ?></span><?php echo "<b>".$msgID."</b>"; echo $msg; ?>
</div>
<?php
}
mysql_close();
?>
<div id="last_msg_loader"></div>
</div>
</body>
</html>
<?php
}
else
{
$last_msg_id=$boxid;
$sql=mysql_query("SELECT * FROM announcements WHERE announce_id < '$boxid' ORDER BY announce_id DESC LIMIT 5");
$last_msg_id="";
while($row=mysql_fetch_array($sql))
{
$msgID= $row['announce_id'];
$msg= $row['content'];
$posted= $row['postedby'];
?>
<div id="<?php echo $msgID; ?>" align="left" class="message_box" >
<span class="number"><?php echo $posted; ?></span><?php echo "<b>".$msgID."</b>"; echo $msg; ?>
</div>
<?php
}
mysql_close();
}
?>
提前致谢!我希望有一个人可以帮助我 :)