I am trying to send a JS variable to a PHP file but it does not seem to be working. In the console its showing an error as an show.php
file. I am not able to understand What I am doing wrong.
function details(id) {
var id = id;
// alert(id);
$.ajax({
type: 'POST',
url: 'show.php',
data: id,
success: function(data) {
alert("hi");
}
});
}
<button onclick="details(<?php echo $id ; ?>)" class="btn btn-rounded btn-primary">Details</button>
show.php:
<?php
if (isset($_POST['id']))
{
$uid = $_POST['id'];
echo json_encode($uid);
}
?>
2
Answers
Write data in json object
see code below
Check your network tab and check the sending parameters list . You have to mention datatype json
Try this
In your show.php