52,782
社区成员
发帖
与我相关
我的任务
分享
//获取不同浏览器的xmlHttpRequest对象
function ajaxFunction(){
var xmlHttp;
try{//Firefox,opera 8.0* safari
xmlHttp= new XMLHttpRequest();
}catch(e){
try{//Internet Explorer
xmlHttp = new ActiveXObject("Msxm12.XMLHTTP");
}catch(e){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
return xmlHttp;
}
window.onload=function(){
document.getElementById("checkusername").onclick=function(){
var username=document.getElementById("username").value;
//1.获取xmlHttpRequest对象
var xmlReq=ajaxFunction();
//2.接受服务器的响应
xmlReq.onreadystatechange=function(){
if(xmlReq.readyState==4){
if(xmlReq.status==200 || xmlReq.status==304){
}
}
}
//3.连接服务器
xmlReq.open("post","RegisterServlet",true);
xmlReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//4.向服务器发送数据
xmlReq.send("username="+username);
}
}