我有一個代碼,當我向下滾動我的頁面,它會從數據庫中加載更多的內容,但我的問題是當我滾動速度太快,內容從數據庫副本,如果我用這個代碼和結果來的是,這將是麻煩爲我的用戶,重複的內容與負載內容,同時向下滾動使用jQuery,PHP
這裏是代碼:
<?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();
}
?>
在先進的感謝!我希望有人能幫助我:)
確保數據加載完整的方法http://api.jquery.com/jQuery.post/ – Breezer