点击后再次阅读更多按钮

时间:2015-08-03 09:59:20

标签: php jquery ajax

我有一个readmore链接,允许人们在点击后阅读更多帖子,我不想要的是按钮再次显示,我也不想让整个帖子再次显示,我只是希望剩余的帖子添加到之前的读者阅读或正在阅读,就像你点击看更多链接时在Facebook页面上完成的那样。

由于



$(function(){
$(".readMore").click(function(event){
	 event.preventDefault();
	var link = $(this).attr('href');
	var dataString = 'link='+ link;
	$.ajax({
		type : "POST",
		url: "readmore-post.php",
		data: dataString,
		cache : false,
		success: function(html){
		$(".read_more").before(html);
				
		}
		
	});
	});
	});

this is the html part 

<?php echo substr($post,0,250); ?>..
<?php
if(strlen($post)>250)
{
echo"<a href='$postID' style='font-size:0.8em;' class='readMore'>readmore</a>  </br>";
}
?>
<div class="read_more"></div>
					
&#13;
&#13;
&#13;

&#13;
&#13;
this is the php part

<?php
include('../config/connect.php');
$read_id = $_POST['link'];
$srm = "SELECT * FROM page_timeline WHERE timelineID='$read_id' ORDER BY timelineID DESC";
$sre = $db->query($srm);
while($rowr = $sre->fetch_array())
{
$postID = $rowr['timelineID'];
$post = $rowr['post'];
}
echo "<p>".$post."</p>";
?>	
						
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

试试这个并查看内联评论

$(function(){
$(".readMore").click(function(event){
        event.preventDefault();
        var that=$(this);
        var link = $(this).attr('href');
        var dataString = 'link='+ link;
        $.ajax({
            type : "POST",
            url: "readmore-post.php",
            data: dataString,
            cache : false,
            success: function(html){
                $(".read_more").empty().append(html); 
                //clear all the contents and append new one to .read_more div 
                that.hide(); //hide the button on successful load
            },
        });
    });
});