See this example on github
In brief
*.js
fetch("post.php", {
method: "post",
mode: "cors",
headers: {
"Content-Type": "application/json"
},
body: {myData: "hello world"}
})
*.php
$data = json_decode(trim(file_get_contents("php://input")));
echo $data["myData"] // prints hello world!