I send json data through ajax to a php file called in case 'receive.php'.
user_name
, user_id
, etc. are defined on top of my script page you may change by anything else.
Here is my js code :
const data = {
name: user_name,
id: user_id,
score: success,
time: endTime
};
const jsonString = JSON.stringify(data);
const xhr = new XMLHttpRequest();
xhr.open("POST", "receive.php", true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(jsonString);
This is my php file
<?php
header('Content-Type' , 'application/json');
$requestPayload = file_get_contents('php://input');
$json = json_decode($requestPayload , true);
$not = 'gsvcgdsqc';
//This gives NULL
var_dump($json);
echo $not;
?>
in the browser (network), i can see sent data :
But when i try to store it in a variable and display it, it gives null :
So how can I access and store those data in a variable so I can use them after for other actions?