function Ajax(){
//创建Ajax 兼容浏览器
var ajax=window.XMLHttpRequest?new window.XMLHttpRequest():ActiveXObject("microsoft.XMLHttp");
//重写onreadystatechange()方法
ajax.onreadystatechange=function(){
//判断ajax状态码
if(ajax.readyState==4){
//判断响应状态码 200为正常接收
if(ajax.status==200){
alert(ajax.responseText)
}
else if(ajax==404){
console.log("资源不存在");
}
else if(ajax==500){
console.log("服务器繁忙");
}
}
}
//发送请求
/*
发送请求有post和get两种方法 get不需要设置请求头post需要
post方式如下:
ajax.open("POST","url");
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send("你所需要传递的值");
*/
ajax.open("GET","UserServlet?name="+name+"&login=checkUname_");
ajax.send(null);
}