Reputation: 41
So what i need is a way to hide load more button when all posts are loaded. There are default 20 posts and load more when clicked returns 10 more. Once all posts are loaded load more button should be hidden.
code from 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 - which outputs 10 more posts
$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");
Upvotes: 1
Views: 1829
Reputation: 6002
Just add a condition within a success block, to check if there are any more items
$(".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();
}
});
});
Happy Coding :)
Upvotes: 2