var username=document.getElementById("username").value;
var password=document.getElementById("password").value;
var formData=new FormData();
formData.append('username',username);
formData.append('password',password);
var xmlHttp;
if (window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp!=null)
{
xmlHttp.onreadystatechange = function () { 
if (xmlHttp.readyState == 4) {  if (xmlHttp.status == 200) {

alert(xmlHttp.responseText);
} else {
}
} else {
}

xmlHttp.open("POST", "admin.php", true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send(formData);
}
php代码echo $_POST["username"];