I am fetching JSON data with CORS and I am getting the JSON data in my console successfully. Now I want to display the fetched data with PHP. What are the next steps after the code below to get the fetched data into PHP?
<script>
fetch("http://localhost:8000/get_users.php", {
method: 'post',
credentials: 'include'
}).then(response => {
return response.json();
}).then(users => {
console.log(users);
});
</script>
I tried to get it in $_POST
:
$posted_data = array();
if (!empty($_POST['users'])) {
$posted_data = json_decode($_POST['users'], true);
}
print_r($posted_data);
But users
is undefined.
Does someone know how to get the fetched JSON users
into PHP?
Thanks!