我的JavaScript发送请求:
var jax = new XMLHttpRequest();
jax.open("POST", "http://localhost/some.php", true);
jax.setRequestHeader("Content-Type", "application/json");
jax.send(JSON.stringify(jsonObj));
jax.onreadystatechange = function() {
if(jax.readyState === 4) { console.log(jax.responseText); }
}
目前我的php只做了以下事情:
print_r($HTTP_RAW_POST_DATA);
print_r($_POST);
从原始的POST数据中得到的输出是对象字符串,但POST数组为空。
{"name" : "somename", "innerObj" : {} ... }
Array
(
)
我需要将数据以正确的格式传递给$_POST
变量,而jQuery不是一个选项。
file_get_contents('php://input')
吗? - Elias Van Ootegem