正在加载+10个帖子


Loading +10 posts

我在home.php中构建了两个函数,以便在提要中加载+10个帖子。它加载了两个带有一个缺陷的新帖子。它复制了它所包含的整个home.php。那就是标题、提要、状态保持器和加载更多选项卡。我不知道为什么。我怎样才能阻止这种情况的发生。也许把流放在自己的页面上,然后自己调用它?

<script>
var global_streamcount=20;
function refreshstream()
{
$.ajax({
method: 'get',
url : 'home.php?limit='+global_streamcount,
dataType : 'text',
success: function (text) { $('#homestatusid').prepend(text); }
});
}
</script>
<script>
function checkautoload(){
global_streamcount=global_streamcount+10;loadstream('home.php','homestatusid',global_streamcount);
}
</script>

HTML加载更多

<div class="stream_show_posts" onClick="global_streamcount=global_streamcount+10;refreshstream();">Show More Posts</div>    

PHP

if(isset($_GET['limit'])){
$sqllimit = $_GET['limit'];
}else{
$sqllimit = 20;
}
$call="SELECT * FROM streamdata WHERE streamitem_target= $following_string OR streamitem_creator = $following_string OR streamitem_creator IN $friendlist AND streamitem_target IN $friendlist ORDER BY streamitem_timestamp DESC LIMIT $sqllimit";

调用应该是对另一个脚本的,但若要保留在同一个文件中,则必须退出脚本,只输出从数据库中提取的项。。类似于:

if(isset($_GET['limit'])){
    if(isset($_GET['limit'])){
        $sqllimit = (int)$_GET['limit'];
    }else{
        $sqllimit = 20;
    }
        $call="SELECT * FROM streamdata WHERE streamitem_target= $following_string OR streamitem_creator = $following_string OR streamitem_creator IN $friendlist AND streamitem_target IN $friendlist ORDER BY streamitem_timestamp DESC LIMIT $sqllimit";
    echo "<div>Your contents echoed with results from db</div>"
    die;
}
// rest of the page ..

我会使用load()函数来实现这一点:

<div class="stream_show_posts">Show More Posts</div>
<script>
    $('div.stream_show_posts').on('click', function() {
        global_streamcount=global_streamcount+10;
        $('#your_posts_div_element').load('home.php?limit='+global_streamcount+' #your_posts_div_element');
    });
</script>

这个函数基本上会从名为"your_posts_div_element"的元素中获取所有数据,并将旧数据替换为页面上相同的元素中的新数据。

此外,请注意,不再建议直接在元素中使用onClick处理程序-这是我使用on()函数将单击事件分配给DIV.