Php AJAX脚本在提要下输出新帖子,如何转到上面?

Php AJAX脚本在提要下输出新帖子,如何转到上面?,php,javascript,jquery,ajax,Php,Javascript,Jquery,Ajax,当点击提要底部的div时,这个AJAX脚本会加载更多的帖子,但我想知道的是如何更改脚本以在提要顶部显示新帖子。。不是底部 源代码: loadmore.php- <?php include('../general_scripts/connect.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-trans

当点击提要底部的div时,这个AJAX脚本会加载更多的帖子,但我想知道的是如何更改脚本以在提要顶部显示新帖子。。不是底部

源代码:

loadmore.php-

<?php
include('../general_scripts/connect.php');

?>
<!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 href="frame.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>

<script type="text/javascript">
$(function() {
//More Button
$('.more').live("click",function() 
{
var ID = $(this).attr("id");
if(ID)
{
$("#more"+ID).html('<img src="moreajax.gif" />');

$.ajax({
type: "POST",
url: "ajax_more.php",
data: "lastmsg="+ ID, 
cache: false,
success: function(html){
$("ol#updates").append(html);
$("#more"+ID).remove();
}
});
}
else
{
$(".morebox").html('no more to display.');

}


return false;


});
});

</script>
<style>
body
{
font-family:Arial, 'Helvetica', sans-serif;
color:#000;
font-size:15px;

}
a { text-decoration:none; color:#0066CC}
a:hover { text-decoration:underline; color:#0066cc }
*
{ margin:0px; padding:0px }
ol.timeline
    { list-style:none}ol.timeline li{ position:relative;border-bottom:1px #dedede dashed; padding:8px; }ol.timeline li:first-child{}
    .morebox
    {
    font-weight:bold;
    color:#333333;
    text-align:center;
    border:solid 1px #333333;
    padding:8px;
    margin-top:8px;
    margin-bottom:8px;
    }
    .morebox a{ color:#333333; text-decoration:none;        width: 400px;   
}
    .morebox a:hover{ color:#333333; text-decoration:none;      width: 400px;   
}
    #container{margin-left:60px;        width: 400px;   
 }

</style>
</head>

<body>
<div id='container'>
<ol class="timeline" id="updates">
<?php
$sql=mysql_query("SELECT * FROM updates ORDER BY item_id DESC LIMIT 16");
while($row=mysql_fetch_array($sql))
{

/* GETS THE NUMBER OF LIKES FOR POST */
$result1 = mysql_query("SELECT * FROM comments");
$comment_count = mysql_num_rows($result1);

/* GETS THE NUMBER OF LIKES FOR POST */
$result2 = mysql_query("SELECT * FROM likes");
$like_count = mysql_num_rows($result2);



?>
<!-- START OF THE HTML STYLING FOR THE UPDATE -->


<div class="title">
  <!-- PRINT USERNAME -->
  <span class="username">&nbsp;<?php print $row['username']; ?></span>
  <!-- PRINT NAME -->
  <span class="name">&nbsp;<?php print $row['name']; ?></span> </div>
<div class="thum" align="center"></div>
<div class="content"><span class="update"><?php print $row['item_content'] ?></span></div>

<div class="under-bar">
  <p class="under-text">&nbsp;comment (<?php print $comment_count ?>) like (<?php print $like_count ?>)&nbsp;&nbsp;&nbsp;<?php print $time_ago ?></p>
</div>
<div class="seperate"></div>



<!-- END OF THE HTML STYLING FOR THE UPDATE -->
<?php } ?>
</ol>
<div id="more<?php echo $msg_id; ?>" class="morebox">
<a href="#" class="more" id="<?php echo $msg_id; ?>">more</a>
</div>

</div>

</body>
</html>
 <?php
include('../general_scripts/connect.php');


if(isset($_POST['lastmsg']))
{
$lastmsg=$_POST['lastmsg'];
$result=mysql_query("SELECT * FROM updates WHERE item_id<'$lastmsg' ORDER BY item_id DESC LIMIT 7");
$count=mysql_num_rows($result);
while($row=mysql_fetch_array($result))
{
$msg_id=$row['item_id'];
$message=$row['item_content'];
?>


<div class="title">
  <!-- PRINT USERNAME -->
  <span class="username">&nbsp;<?php print $row['username']; ?></span>
  <!-- PRINT NAME -->
  <span class="name">&nbsp;<?php -print $row['name']; ?></span> </div>
<div class="thum" align="center"></div>
<div class="content"><span class="update"><?php print $row['item_content'] ?></span></div>

<div class="under-bar">
  <p class="under-text">&nbsp;comment (<?php print $comment_count ?>) like (<?php print $like_count ?>)&nbsp;&nbsp;&nbsp;<?php print $time_ago ?></p>
</div>
<div class="seperate"></div>


<?php
}


?>

<div id="more<?php echo $msg_id; ?>" class="morebox">
<a href="#" id="<?php echo $msg_id; ?>" class="more">more</a>
</div>

<?php
}
?>

$(函数(){
//更多按钮
$('.more').live(“单击”,函数()
{
var ID=$(this.attr(“ID”);
如果(ID)
{
$(“#更多”+ID).html(“”);
$.ajax({
类型:“POST”,
url:“ajax_more.php”,
数据:“lastmsg=“+ID,
cache:false,
成功:函数(html){
$(“ol#更新”).append(html);
$(“#更多”+ID).remove();
}
});
}
其他的
{
$(“.morebox”).html('不再显示');
}
返回false;
});
});
身体
{
字体系列:Arial,'Helvetica',无衬线;
颜色:#000;
字体大小:15px;
}
a{文本装饰:无;颜色:#0066CC}
a:悬停{文本装饰:下划线;颜色:#0066cc}
*
{边距:0px;填充:0px}
时间线
{列表样式:none}ol.timeline li{位置:相对;边框底部:1px#dedede虚线;填充:8px;}ol.timeline li:第一个子{}
莫博克斯先生
{
字体大小:粗体;
颜色:#333333;
文本对齐:居中;
边框:实心1px#333333;
填充:8px;
边缘顶部:8px;
边缘底部:8px;
}
.morebox a{颜色:#333333;文本装饰:无;宽度:400px;
}
.morebox a:悬停{颜色:#333333;文本装饰:无;宽度:400px;
}
#容器{左边距:60px;宽度:400px;
}
注释()如()

注释()如()


您需要将附加更改为前置。Append将其添加到底部,prepend添加到顶部

改变

$("ol#updates").append(html);


您需要将附加更改为前置。Append将其添加到底部,prepend添加到顶部

改变

$("ol#updates").append(html);