I have tried to echo my json into my html page with php, but it only prints in console or gives back an error.
I’m pretty new to this so please help.
this is the javascript with fetch and activated onclick to submit one to php
async function hey(){
let click = 1;
await fetch('data.php',{
method: 'POST',
header: {
'Content-Type': 'application/json',
},
body: JSON.stringify(click),
}).then(response => response.json())
.then(data => {
console.log(data);
})
.catch((error) => {
console.error(error);
});}
this is the php but it will only ever print to the console
<?php
$json = file_get_contents('php://input');
echo $json;
?>