2017-04-08 41 views
-1

加载评论其他自动像Facebook如何加载他人的意见与出页面refresshing

** PHP代码更新**

<section class="panel-body"> 

<div class="container"> 

<div class="comment"> 
<div class="commenter" name="comments"> 
<img width="80px" height="80px" src="uploads/<?php echo $row['photo']; ?>"> 

</div> 
    <div class="comment-text-area"> 
     <textarea class="textinput"id="comment" name="comments" placeholder="Comment Here......"></textarea> 
    <button type="submit" class="butn"name="compost">post comment</button> 


    </div> 
</div> 
</div> 

    </div>   
</fotm> 


     <div id="comments"> 
<?php include'cajax.php'; ?> 
    </div> 



</section> 
</section> 


    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"> 
</script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
$('#comments').load('cajax.php'); 
refresh(); 
}); 

    function refresh() 
{ 
    setTimeout(function() { 
    $('#comments').load('cajax.php'); 
    refresh(); 
    }, 1000); 
} 
    </script> 

如何在不网页自动加载评论刷新我知道它的 可能与阿贾克斯,但如何实现代码,请帮助我们

+1

你需要“加载更多按钮”这里是演示页面和代码http://www.codexworld.com/load-more-data-using-jquery-ajax-php -from-database/ – Mario

+0

看到我的请求请 –

+0

那么你有错题目的话题,“我如何发表评论,而不刷新页面” – Mario

回答

0

首先创建另一个名为comments.php的php文件或任何你想要的,并剪切和粘贴从该文件中获取注释的代码 并在你想要显示注释的主文件中创建一个div,id = “意见”或任何你想要的..而该div里面包括新的PHP文件中像这样

<div id="comments"> 
<?php include'comments.php'; ?> 
</div> 

现在上面的代码粘贴下面的JavaScript代码:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"> 
</script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
$('#div_name').load('filename.php'); 
refresh(); 
}); 

function refresh() 
{ 
    setTimeout(function() { 
     $('#div_name').load('filename.php'); 
     refresh(); 
    }, 1000); 
} 
</script> 

替换用的div_name你的div的名字和filename.php ..与你的文件名

相关问题