I try to hand over a parameter, a String, that is determined by user input via Ajax to a PHP Programm, but the php does not receive the parameter I try to handover. Then Ajax should return a JSON
const category = document.getElementById('genreSelect').value;
$.ajax({
type: 'GET',
url: 'button.php',
data: { category: category } ,
success: function(response) {
console.log(response);
}
});
<?php
header('Content-Type: application/json');
$kate ="";
if(isset($_POST['category'])) {
$name = $_POST['category'];
$kate =$name;
echo $name;
} else {
echo "No name parameter received.";
}
echo json_encode($kate);
?>
I have tried several other Ajax commands, but they did not work.