$_POST is not being filled after the use of XMLHttpRequest in JS.
HTML + JS:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>T</title>
</head>
<body>
<button id="press">Sample button</button>
</body>
<script>
document.querySelector('#press').addEventListener('click', function() {
var js = JSON.stringify({
name: "String"
});
var req = new XMLHttpRequest();
req.open('POST', 'P.php/');
req.setRequestHeader('Content-type', 'application/json; charset=utf-8');
req.send(js);
req.onload = function() {
alert(req.response);
}
});
</script>
</html>
PHP is just an ” echo $_POST[“name”] “; it results in an error (Undefined array key “name”), im expecting to get “String” in req.response