I created a ajax request in Javascript using json, but the $_POST variable is empty.
var userid = "james";
var score = 200;
var jsondata = {
userid: userid,
score: score
};
data = JSON.stringify(jsondata);
req = new XMLHttpRequest();
req.setRequestHeader("Content-Type", "application/json");
req.open("POST", 'functions.php', true);
req.send(data);
My functions.php file looks like this:
print "CONTENT_TYPE: " . $_SERVER['CONTENT_TYPE'] . "<BR />";
$data = file_get_contents('php://input');
print "DATA: <pre>";
var_dump($data);
var_dump($_POST);
var_dump($_GET);
However all of this gives me an empty array. Any help, please?