AJAX脚本在提要下输出新帖子,我如何移动到上面
AJAX script outputs new posts under feed, how do i move to above?
当点击提要底部的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"> <?php print $row['username']; ?></span>
<!-- PRINT NAME -->
<span class="name"> <?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"> comment (<?php print $comment_count ?>) like (<?php print $like_count ?>) <?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>
ajax_more.php——
<?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"> <?php print $row['username']; ?></span>
<!-- PRINT NAME -->
<span class="name"> <?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"> comment (<?php print $comment_count ?>) like (<?php print $like_count ?>) <?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
}
?>
金额很抱歉,只是不想错过任何东西。我不是要求你写任何代码,而是简单地指出我如何改变这一点,哪一部分使它在提要下面输出。不是顶部。谢谢你:D !
您需要将您的追加更改为前置。Append将其添加到底部,prepend添加到顶部。
改变$("ol#updates").append(html);
$("ol#updates").prepend(html);
相关文章:
- 如何将模板中的标记脚本移动到.js文件中
- jQuery-将列表项的一个元素移动到同一项的另一个元素中+对我的列表中的每个项执行此操作
- 从setInterval方法移动到带有sprite的requestAnimationFrame
- 通过DRAGGABLE将一个DIV移动到另一个DIF下?(CSS,JQuery)
- 将第二窗口移动到第二屏幕或特定屏幕
- 未捕获的类型错误:无法设置属性'innerHTML'如果为null,则将脚本移动到正文不会;不起作用
- 如何在鼠标悬停时将对象从起始位置移动到结束位置,然后在鼠标悬停后再次移动
- 将元素移动到右侧,然后返回到左侧
- 文件的节点自动化移动到另一个文件夹中
- 将插入符号位置移动到ContentEditable<DIV>
- 交互.js拖动的项目移动到顶部
- 麻烦将coffee脚本片段移动到rails中自己的类中
- Parsley.js,多步骤表单,在移动到上一步时跳过验证
- 用于文件移动到另一个文件夹的Javascript自动化
- 如何使用tweenJS使位图移动到某些点
- 传递表单值并移动到另一页
- 如何使用jquery将所选项目从一个下拉组列表(optgroup)移动到另一个下拉列表(optgroup)
- Jquery.focus未移动到必填字段
- 将焦点移动到页面元素
- AJAX脚本在提要下输出新帖子,我如何移动到上面