我正在尝试从 POST 请求中获取 JSON 信息。我的 POST 请求是:
var money = document.getElementById("code").value;
const Http = new XMLHttpRequest();
const url='/paypal/';
Http.open("POST", url);
Http.setRequestHeader("Content-Type", "application/json");
Http.send(JSON.stringify({
value: money
}));
控制器是:
public function paypal(Request $r) {
$postInput = file_get_contents('php://input');
$data = json_decode($postInput, true);
$response = array('value' => $data);
return Response::json($response);
}
但我得到的唯一结果是:
{"value":null}
知道我的问题在哪里吗?