Answer the question
In order to leave comments, you need to log in
Sending JSON via XHR using the POST method - how to accept and parse?
Good day. I'll get right to the point - There is an XMLHttpRequest written in pure JS:
var r = new XMLHttpRequest();
r.open("POST", "model.php");
r.setRequestHeader("Content-Type", "application/json");
r.send("req="+json);
{"name":"username", "email":"usermail" }
var_dump(json_decode($_POST["req"]));
Notice: Undefined index: req in ...
NULL
Answer the question
In order to leave comments, you need to log in
www.stackoverflow.com/a/8945912$entityBody = file_get_contents('php://input');
I did the following based on your advice:
$req = json_decode(file_get_contents("php://input"));
echo $req -> name; # Выведет то, что должно. Работает.)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question