I have a form that contains just two buttons, a like and a dislike button. Each button gets the ID of a product in the 'action' section of the button and I want to pass that to a php file that contains a pdo function to submit a like/dislike to my database, but I don't want the page to refresh.
I am really new to AJAX and have no clue on how to use it to solve this problem. Below is the relevant code, I'm wondering if I can get any tips on how to use AJAX with the code I have?
index.html
<form id="likeDislike" class="form-horizontal" action="index.php?id=' . $productData->getID() .'" method="post">
<button id="like" type="submit" name="like" value="like" class="btn btn-success"><i class="glyphicon glyphicon-thumbs-up"></i></button>
<button id="dislike" type="submit" name="dislike" value="dislike" class="btn btn-danger"><i class="glyphicon glyphicon-thumbs-down"></i></button>
</form>
index.php
if (isset($_POST["like"])) {
$productDataSet = new productDataSet();
$productDataSet->addLike();
}
if (isset($_POST["dislike"])) {
$productDataSet = new productDataSet();
$productDataSet->addDislike();
}