async function postData(url = '', data = {}) {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
return await response.json();
}
postData('/handler.php', { number: 42 })
.then((data) => {
console.log(data.number);
});
$number = (int)$_POST['number'];
$number += 1;
echo json_encode(['number' => $number]);