ajax的验证用户是否正确的,,有点不明白
<html>
<head>
<title>judegUsername.axpx</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script language="JavaScript" type="text/javascript">
var request = false;
try{
request = new XMLHttpRequest();
}catch(microsoftIE){
try{
request = new ActiveXObject("Msxml2.XMLHTTP");
}catch(microsoftOldIE){
try{
request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(failed){
request = false;
}
}
}
if(!request){
alert("初始化XMLHttpRequest对象失败");
}
function sendUsername(){
var username = document.getElementById("username").value;
if(username!=null && username!=""){
var url = "./judgeUsername.axpx?username="+escape(username);
request.open("get",url,true);
request.onreadystatechange=updatepage;
request.send(null);
}
}
function updatepage(){
if(request.readyState==4){
if(request.status==200){
document.getElementById("reusername").innerHTML = request.responseText;
//document.getDocumentById("reusername").innerText = request.responseText;
}else if(request.status==404){
alert("找不到页面!");
}else{
alert("错误代码:"+request.status);
}
}
}
function clearMessage(){
document.getElementById("reusername").innerHTML = "";
}
</script>
</head>
<body>
<form action="/register.jsp" method="post">
<table align="center">
<caption>guoyongfei为已注册,其他均未注册</caption>
<tr><th>用 户 名:</th><td><input type="text" name="username" id="username" onblur="sendUsername()" onfocus="clearMessage()"/></td><td width="40%" id="reusername"></td></tr>
<tr><th style="height: 26px">密 码:</th><td style="height: 26px"><input type="password" name="password" id="password"/></td><td width="20" style="height: 26px"></td></tr>
<tr><th>密码确认:</th><td><input type="text" name="surePassword" id="surePassword"/></td><td width="20"></td></tr>
</table>
</body>
</html>
在另一个弹出页面 judgeUsername.axpx 的page_load:
//这里要写什么?
//System.out.println("username:"+username);
if (username.Equals ("guoyongfei"))
{
Response.Write("<font color='red'>用户名已经注册</font>");
}
else
{
Response.Write("<font color='green'>用户名可以用</font>");
}
------解决方案--------------------