common.js
var objRequest;
function getajax()
{
try
{
objRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
objRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc)
{
objRequest=null;
}
}
}
function Isname()
{ getajax();
var name = document.getElementById("name").value;
if(!objRequest&&typeof XMLHttpRequest!="undefined")
{objRequest=new XMLHttpRequest();}
var url="check.asp?action=Isreg&name="+escape(name);
if(objRequest!=null)
{
objRequest.onreadystatechange = nameProcess;
objRequest.open("GET",url,true);
objRequest.send(null);
}
}
function nameProcess()
{
var objname = document.getElementById("nametest");
if(objRequest.readyState<4){
objname.innerHTML="正在检测……";
}
else if(objRequest.readyState == 4){
var response = objRequest.responseText;
objname.innerHTML=unescape(response);
}
else{
objname.innerHTML = "Error:"+objRequest.statusText;
}
}
check.asp
<!--#include file="conn.asp"-->
<%if Request.QueryString("action")="Isreg" then
name=Request.QueryString("name")
set Isins=conn.Execute("select [name] from [user] where [name]='"&name&"'")
if (Isins.bof and Isins.eof) then
response.write "该用户名可以注册!"
else
response.write "该用户名已被注册!"
end if
set Isins=nothing
end if%>
register.htm
<script type="text/javascript" src="common.js"/></script>
用户名:<input name="name" type="text" id="name" size="16" maxlength="16" onChange="Isname();"><span id="nametest"></span>
|