<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script>
window.onload = function(){
document.getElementById('btn').onclick = function(){
var req = new XMLHttpRequest();
var username = document.getElementById('username');
var name = decodeURIComponent(username.value);
req.open('post','ajaxr.php?username='+name);
req.onreadystatechange = function(){
if(req.readyState == 4 && req.status == 200){
alert(req.responseText);
}
}
req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
req.send('name='+name);
}
}
</script>
</head>
<body>
<input type="text" id="username">
<input type="button" id="btn" value="click">
</body>
</html>
<?php
var_dump($_POST);