日期:2014-05-16 浏览次数:20733 次
function cleck(ouser){
var uname=ouser.value;
if(!uname){
alert("不能为空");
ouser.focus();
return;
}
var url="Reg";
xmlHttpRequest = createXmlHttpRequest();
xmlHttpRequest.onreadystatechange=fanhui;
xmlHttpRequest.open("POST",url,true);
xmlHttpRequest.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
xmlHttpRequest.send("uname="+uname);
}
function createXmlHttpRequest(){
if(window.XMLHttpRequest){
return new XMLHttpRequest();
}else{
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function fanhui(){
alert("调用");
if(!xmlHttpRequest.readyState==4 && xmlHttpRequest.status==200){
alert("调用2");
var result=xmlHttpRequest.responseText;
result=result.replace(/(^\s*)|(\s*$)/g,"");
if(result=="true"){
alert("已存在");
}else{
alert("可以使用");
}
}
}
<table>
<form name="Reg" method="get" action="Reg">
<tr>
<td>用户名:</td>
<td><input type="text" name="uname" onblur="cleck(this)"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="psd"/></td>
</tr>
<tr>
<td>提交:</td>
<td><input type="submit" name="psds" value="提交"/></td>
</tr>
</form>
</table>
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
String uname=request.getParameter("uname");
System.out.println(uname);
boolean uExists=false;
if("hehe".equals(uname)){
uExists=true;
out.print(uExists);
}else{
out.print(uExists);
}
out.flush();