var ajax = null;
if(window.XMLHttpRequest){//创建Ajax对象
ajax = new XMLHttpRequest();
}else if(window.ActiveXObject){
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
if(ajax){//如果创建Ajax对象成功
var url = "login.inc.php";//设置Ajax访问的页面路径
var pStr = "username=root&pwd=root";//需要post的数据用&符号链接起来
ajax.open("POST",url ,true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");//设置访问的http头
ajax.send(pStr);//提交数据
ajax.onreadystatechange = function(){
if(ajax.readyState == 4 && ajax.status == 200){
alert(ajax.responseText);//弹出php页面的返回信息
}
}
}else{
alert("Create Ajax Fail");return false;
}