I use vanilla JavaScript to send an AJAX 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 it's $_POSTempty. There are several related questions about 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 fall into $_POST, so this should be possible. My question is: how? What can i do wrong? Or what can I change?
source
share