let jsVariable = <?= $phpVariable ?>;
fetch('/some/url', {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify({some: 'object'})
}).then(res => res.json()).then(json => {
console.log(json);
})