index.php file:
<?php
$content = file_get_contents("php://input");
$object = json_decode($content);
echo var_dump($object);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button onclick="hello()"> noice </button>
<script>
function hello() {
const data = {hello: "world"};
const xhr = new XMLHttpRequest();
xhr.open("POST", "index.php");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(data));
}
</script>
</body>
</html>
from index.php sending a ajax post request with some data to the same index.php and trying to view the fetched data from index.php file but nothing happens. But the file is received by the browser and not updating.

My question is am I doing something wrong? and how to achieve this?