I'm using vanilla JavaScript to send a AJAX post request with JSON data:
xhr.open(method, url,true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify(data));
The headers look good, but in PHP $_POST
is empty. There are several related questions on SO about this, like this one, but they all suggest using:
json_decode(file_get_contents("php://input"))
However, if I use jQuery.post
my variables end up in $_POST
, so it must be possible. My question is how? What might I be doing wrong? Or what could I change?