<?
if($_POST) exit(print_r($_POST, 1));
?>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript">
function send() {
var data = {
name: "Вася",
surname: "Петров"
},
send_data = Object.entries(data).map(m => m.join('=')).join('&'),
xhr = new XMLHttpRequest();
xhr.open("POST", location);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onload = function() {
if (xhr.status == 200) {
alert(xhr.responseText)
}
}
xhr.send(send_data);
}
</script>
</head>
<body>
<button onclick="send()">Send</button>
</body>
</html>
Сохранить под любым именем и выполнить. Работает?