- AJAX-GET提交方式:
function ls1(username) {
var xmlHttp;
if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}else{
xmlHttp=new ActiveXObject("Microsoft.XMLHttp");
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
if(xmlHttp.status == 200){
var nameTipMsg=document.getElementById("nameTipMsg");
nameTipMsg.innerHTML=xmlHttp.responseText;
}else{
alert(xmlHttp.status);
}
}
}
var timeStamp=new Date().getTime();
xmlHttp.open("GET","checkusername.do?_="+timeStamp+"&username="+username,true);//这里只开启通道,不发送请求,为了解决ajax-get请求缓存问题,可以加个时间戳
//4.通知异步请求对象代替浏览器发送请求协议包
xmlHttp.send();
}
2.AJAX-POST提交方式:
比GET提交方式多这几行代码
xmlHttp.open("POST","URL",true);//这里只开启通道,不发送请求
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
//4.通知异步请求对象代替浏览器发送请求协议包
xmlHttp.send("username="+username+"&password="+password);