当我使用 fetch 发送数据时 $_POST 上的空数组

Empty array on $_POST when I send data with fetch

我正在尝试使用 fetch 将数据从 JavaScript 发送到 PHP 但在 PHP 中,当我执行 $_POST 时我得到空数组。

async function updatesProf(data) {

    const dataUpdate = {
        method:"POST",
        headers: {
            'Accept':'application/json',
            'Content-Type':'application/json',
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        body: JSON.stringify({ data: data })
    };

    await fetch('synthese', dataUpdate)
    .then(response => response.json()).then(res => data )
    .catch(error => console.log("Error: "+error));

}

经典问题,如果您使用 Javascript 发送 $_Post。

试试:

$_POST = json_decode(file_get_contents('php://input'), true);
if(isset($_POST)){
    var_dump($_POST); 
}