2
Hello, good afternoon!
I’m having a problem that I don’t know how to solve. I don’t know how to program in Jquery or Ajax, but I intend to start learning. How can I make the following PHP code work in Ajax or JS? Which of the two options is better to perform this action of "Like"?
<li>
<form action="like-post.php" method="post">
<button name="id" value="<?= $post["id"] ?>" class="like-post">Like</button>
</form>
</li>
<li class="likes">
<?php
echo $post["likes"];
?>
</li>
Code of the like-post page:
include("header.php");
include("conecta.php");
include("functions.php");
$id = $_POST['id'];
like($conecta, $id);
header("Location: index.php");
die();
What I want to do is with that button as soon as clicked it add one more likes to the post. Thanks in advance!
Thank you very much! But like I said, I don’t understand almost anything about js (basics). How can I return the Ikes to a certain div?
– João Victor Valentim
The code I’m using is an echo $post['Likes'] inside a div with the class "Likes"
– João Victor Valentim
@Joãovictorvalentim I edited, then
response
isnumeroDeLikes
– Lucas
Sorry, I still can’t understand. Inside the Success part in the js file I need to put something? And this variable number I put inside the div where I want the Ikes to appear, right? Because I used the code above but it turns out that this variable is not defined..
– João Victor Valentim
@Joãovictorvalentim you assign the total of Ikes that comes from your bank to her, edited with a fixed value.
– Lucas
I haven’t gotten it yet :/ But thanks for the help. I’m going to start a study in Ajax and Jquery to improve it
– João Victor Valentim