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"];
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"];
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
这行注释掉
xmlHttp.send(formData); 中
formData 应是 键=值[[&键=值]...] 这样格式的串