Как сделать так, чтобы мои кнопки like работали
When i submit my review and through ajax succes, reload comment div only.. it gets submitted but like and dislike button stop working and works only when i reload the whole page. How can i fix this?
<!--CID like --> <script> $(document).ready(function(){ $(".count2").click(function(){ var id = $(this).attr("name"); var c = "counter2"; c = c + id; saveData(c,id); $("#" + c).load(); }); function saveData(c,x){ $.ajax({ type: "POST", url: "Ccounter.php", data: { count: "1", id : x} }) .done(function( count ) { $("#" + c).html(count); }) .fail(function() { // alert( "error" ); }); } }); </script> <!-- like --> <!--CID dislike --> <script> $(document).ready(function(){ $(".count3").click(function(){ var id = $(this).attr("name"); var c = "counter3"; c = c + id; saveData(c,id); $("#" + c).load(); }); function saveData(c,x){ $.ajax({ type: "POST", url: "Cdecounter.php", data: { count: "1", id: x } }) .done(function( count ) { $("#" + c).html(count); }) .fail(function() { // alert( "error" ); }); } }); </script> <!-- dislike -->
<?php require_once __DIR__ . "/config.php"; $star->id = "index_page"; include "database.php"; $sql ="SELECT * FROM review where prod_Id = '$prodId' ORDER BY CID DESC"; $query = mysqli_query($conn,$sql); // output data of each row while($row = mysqli_fetch_assoc($query)) { $cid= $row["CID"]; $id = $row["CID"]; $name = $row["Name"]; $comm = $row["Comment"]; ?> <div class="media" style="width:100%;height:100%; border-color:#000000; border-radius: 5px;box-shadow: 5px 5px 5px #888888;"> <div style="float:right;"> <?php echo $star->getRating("size-2"); ?> </div> <h5 style="display:inline-block;margin-bottom:0.4em;font-size:4;font-size: 25px;color:#6d7585"> <?php echo $name;?></h5> <div class="media-left"> <a href=""> <img src="images/user.jpg" title="User" alt=" " /> </a> </div> <div class="media-body"> <?php echo "<p>".$comm."</p>"; echo "<span><a id='count2' class='count2' name='".$id."'><img src='images/Like.png' width='20px' height='20px' title='Like' alt=' ' /></a> "; ?> <div id="counter2<?php echo $id;?>" style="width:10px;display:inline-block;margin-right:15px;"> <?php $fetch1=mysqli_query($conn,"select `Up` from review where CID = '$cid'"); $fetch2=mysqli_fetch_array($fetch1); $counter=$fetch2['Up']; echo $counter; echo "</div><a id='count3' class='count3' name='".$id."'><img src='images/Dislike.png' width='20px' height='20px' title='DisLike' alt=' ' /></a> "; ?> <div id="counter3<?php echo $id;?>" style="width:10px;display:inline-block;margin-right:10px;"> <?php $fetch1=mysqli_query($conn,"select `Down` from review where CID = '$cid'"); $fetch2=mysqli_fetch_array($fetch1); $counter=$fetch2['Down']; echo $counter; echo"</div> <a onclick = 'showForm(1".$id.")' >Reply </a><a onclick = 'showForm1(2".$id.")' >Edit </a><span style='float:right;'>".$row['Time_Stamp']." </span></span>"; include('reply.php'); include('edit.php'); echo "</div> <br> </div>";
Что я уже пробовал:
я пытался перезагрузить различные div по очереди, но каждый раз терпел неудачу.