how to append my click result in ajax success?
i made simple like code that can any user inside the chat room can make like for public message
- <?php
-
- // Set the header to accept JSON
- // Insert your database connection here (should probably use mysqli)
- $host = "localhost"; // or IP or whatever
- $db_user = "root";
- $db_pass = "xx";
- $db_name = "x";
- mysql_connect($servername, $db_user, $db_pass) or mysql_error();
- mysql_select_db($db_name) or db_name();
- // Grab user id from post data
- if (isset($_POST['likeid'])){
- // Write the query
- $sql_select = mysql_query("SELECT likes FROM chat WHERE likes > 1");
- $sql_update = "UPDATE chat SET likes = likes +1 WHERE post_id = '" . (int)$_POST['likeid'] . "'";
-
- $_SESSION["likeid"]= $_POST["likeid"];
- echo "Yes, Like Sent";
- } else {
- echo "N0, Like is not set";
- // Encode a JSON response if the query is successful
- }
- if(mysql_query($sql_update)){
- echo("Success");
- }
- // this is the php variables to show the like container for each message
- $likedom ="<input type='hidden' name='likeid' value='" . (int)$chat['post_id'] . "' />
- <div class=\"container\">
- <button class=\"like-button\" value=\"" . $chat['post_id'] . "\"> <i class=\"fa fa-gratipay fa-2x like-icon\"></i><like name=\"showlike\" id=\"counter\">" . $chat['likes'] . "</like></button>
- </div>";
- ?>
and my ajax code
- $(document).on('click', '.like-button', function(){
- var id=$(this).val();
- var $this = $(this);
- $.ajax({
- type: "POST",
- url: "likes.php",
- data: {
- likeid: id,
- increment: true,
- like: 1,
- },
- success: function(data){
- console.log(data);
- }
- });
- });
Everything is working fine..just i have simple problem
when the user click on the like button the click count not showing
but the click count stored in the mysql row ( working fine )
what i need to show the click +1 on the notification like this pic
Thanks