所以我需要的是一种在加载所有帖子时隐藏加载更多按钮的方法。默认情况下有20个帖子,点击后加载更多10个帖子。加载所有帖子后,应隐藏更多按钮。
来自 profile.php 的代码
$(".more").click(function(){
var id=$(".output:last").attr("id");
var split=id.split("output");
var newid=split[1];
var did="<?php echo $did; ?>";
var logid=$("#ssesid").attr("value");
$.ajax({
url:"exp.php",
type:"POST",
data:"newid=" + newid + "&did=" + did + "&logid=" + logid,
success:function(data){
$(".output:last").append(data);
$("#more_load").hide();
}
});
});
exp.php - 输出10个帖子
$osql=mysql_query("SELECT * FROM answer WHERE respond IS NOT NULL AND question_id='$did' AND id < '$newid' and pinned = '0' order by id desc LIMIT 10");
答案 0 :(得分:2)
只需在成功区块中添加条件,以检查是否还有其他项目
$(".more").click(function(){
var id=$(".output:last").attr("id");
var split=id.split("output");
var newid=split[1];
var did="<?php echo $did; ?>";
var logid=$("#ssesid").attr("value");
$.ajax({
url:"exp.php",
type:"POST",
data:"newid=" + newid + "&did=" + did + "&logid=" + logid,
success:function(data){
$(".output:last").append(data);
if(data.size()<10 ) //assuming data contains posts within <li> </li> tags
$(".output:last").append("<li>Sorry No More Records Found!!!</li>");
$("#more_load").hide();
}
});
});
快乐编码:)