So i want to post 2 values from my html code to the php code 1 value is - up or down 2 value is - post id
I have posts and when users clicks on up it posts up, post_id
<script>
function vote(val)
{
var params = {"vote":val.id};
$.ajax({
data: params,
url: 'vote.php',
type: 'post',
success: function (response) {
}
});
}
</script>
<a id='up' class='fas fa-angle-up' onclick='vote(this);'></a>
vote.php
if(!empty($_POST['vote'])) {
if ($_POST['vote']=='up')
{
// Also some how should get second value i think it's done with $_POST['id']
}
if ($_POST['vote']=='down')
{
// Also some how should get second value i think it's done with $_POST['id']
}
}
Actually i don't really know where i should add post_id since id in a tag is already taken
You can extend your function with a parameter to up and down vote
<script>
function vote(vote, val)
{
var params = {"vote": vote, "id": val.id};
$.ajax({
data: params,
url: 'vote.php',
type: 'post',
success: function (response) {
}
});
}
</script>
<a id='up' class='fas fa-angle-up' onclick='vote("up",this);'></a>
<a id='down' class='fas fa-angle-down' onclick='vote("down",this);'></a>
In your PHP code you can now use $_POST['id']
to retrieve the id and $_POST['vote']
to retrieve the down or up vote.