0

I want to display each post with it's corresponding div, but it is not working. It is working in console but not working in HTML.

Any ideas about how i can fix this? Thanks in advance.

Here is my demo code

             ` <div class="post">
               <span class="total-likes></span>
              </div>
              <div class="post">
               <span class="total-likes></span>
              </div>
            <div class="post">
               <span class="total-likes></span>
              </div>
             $('.post').each(function(argument) {
             let post_id=$(this).attr('data-target');
             $.ajax({
             url:'total_likes.php',
             type:'post',
             data:{
             'post_id':post_id
            },
           success:function(data){
           alert(data);
            $(this).find('.total-like').html(data);
          //$('.total-like',this).html(data);
           }
          });
           })

   total-likes.php

            <?php  
            include 'conn.php';
             $sql5 = "SELECT * FROM `post_record` WHERE `id_post` = '".$_POST['post_id']."'";
            $stmt5=$conn->prepare($sql5);
             $stmt5->execute();
            while($row5 = $stmt5->fetch()){
             echo $row5['total_likes']; 
         }
         ?>
  

`

Debaraj Stha
  • 1
  • 1
  • 5

0 Answers0