2012-09-06 68 views
0

我在我的home.php中建立了两个函数来加载我的提要中的+10帖子。并且它会将这两个新帖子加载一个缺陷。它复制了它所包含的整个home.php。这是标题,提要,状态持有者和加载更多选项卡。我不知道为什么。我怎样才能阻止这种情况发生。也许可以把这个流放到自己的页面中并自己调用它?加载+10帖子

<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"; 
+0

对于脚本/页面/程序无法读取您的想法,这是**不是罕见的。你的AJAX请求与普通的get请求有什么不同,所以你的页面会知道它不会显示标题,菜单,页脚...? –

回答

1

调用应该是另一个脚本,但如果你想保持在同一个文件,你必须退出你的脚本和输出只从数据库中提取物品..类似于:

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 .. 
+0

好吧,昨晚我把整个饲料放入homestatus.php并将其包含在家中。将网址更改为:'homestatus.php?limit ='+ global_streamcount,并在点击时发生任何事情。 – dave

+0

如果你直接访问'homestatus.php?limit = 20'它显示什么? –

+0

我会试试看。 – dave

0

我会用load() function来实现:

<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分配单击事件。

+0

我必须保持其他功能吗?因为上述不起作用。 – dave

相关问题