-1

Loading comments others automatically like facebook

**php code updated **

 <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>

how to load comments automatically without page refreshing I know its possible with ajax but how to implement code please help us

Munna VMC
  • 35
  • 1
  • 9

1 Answers1

0

first create another php file named comments.php or whatever you want and cut and paste the code that fetch the comment from DB in that file And in your main file where you want to show comments create a div , id="comments" or whatever you want .. and inside that div include the new php file like this

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

now above that code paste the following javascript code:

<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>

Replace the div_name with the name of your div and filename.php .. with your file name

Abro
  • 16