<script type="text/javascript">
var xmlHttpRequest;
function createXMLHttpRequest(){
if(window.XMLHttpRequest){
xmlHttpRequest = new XMLHttpRequest();
}else{
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function checkUserID(userid){
createXMLHttpRequest();
xmlHttpRequest.open("POST","checkUserServlet?id=" + userid);
xmlHttpRequest.onreadystatechange = checkUserIDCallBack;
xmlHttpRequest.send(null);
}
function checkUserIDCallBack(){
if(xmlHttpRequest.readyState==4){
if(xmlHttpRequest.status==200){
var text = xmlHttpRequest.responseText;
if(text=="true"){
document.getElementById("msg").innerHTML = "用户名已存在,不能注册";
}else{
document.getElementById("msg").innerHTML = "用户名不存在,可以注册";
}
}
}
}
</script>
</head>
<body>
<h1>用户注册</h1>
<hr>
<form action="" method="post">
用户ID:<input type="text" name="userid" onblur="checkUserID(this.value)"><span id="msg"></span><br>
用户名:<input type="text" name="name"><br>
密码:<input type="text" name="password"><br>
<input type="button" value="登录">
</form>