u_name=Request.QueryString("u_name")
if u_name 存在 then
Response.write "0"
else
Response.write "1"
end if2.客户端HTML设计:
一、JavaScript代码 代码片段
<script language=javascript>
function check_user_exists(form){
u_name=form.u_name.value;
if (u_name==null||u_name==‘‘){
alert("请您输入用户名");
return false;
}
infoBoard=document.getElementById("checkInfo");
infoBoard.innerText=‘查询中...‘;
myurl=location.protocol+"//"+location.hostname+"/CheckUser.asp?u_name="+u_name;
retCode=openUrl(myurl);
switch(retCode){
case "-2":
infoBoard.innerHTML=‘<font color=red>抱歉[/red],查询失败‘;break;
case "1":
infoBoard.innerHTML=‘<font color=red>恭喜[/red],‘+u_name+‘可以使用‘;break;
case "0":
infoBoard.innerHTML=‘<font color=red>抱歉[/red],用户名‘+u_name+‘已经被使用‘;
}
return;
}
function openurl(/url){
var objxml=new ActiveXObject("Microsoft.XMLHttp")
objxml.open("GET",url,false);
objxml.send();
retInfo=objxml.responseText;
if (objxml.status=="200"){
return retInfo;
}
else{
return "-2";
}
}
</script>二、HTML表单设计: 代码片段
<form name=form1 action="XXXX.asp" method="post">
<input type=text name=u_name><span id="checkInfo"></span>
<input type=button name=checkuser value="检测用户是否存在" onClick="check_user_exists(this.form);">
</form>