#2
ming2062008-04-23 09:37
|
<script language="javascript">
function checkName(NameStr)
{
if(NameStr.replace(/\s/g,"")=="")
{
document.form1.type.focus();
alert("用户名不能为空!");
}
else
{
var xmlhttp =new ActiveXObject ("Microsoft.XMLHTTP");
xmlhttp.open("post","test.asp?uName="+NameStr,false);
xmlhttp.setrequestheader("contrn-type","text/xml");
xmlhttp.setrequestheader("contrn-charset","gb2312");
xmlhttp.send();
if(xmlhttp.responseText==0) {
alert("已经存在相同的用户名");
}
else{
alert("对不起,你不能使用");
}
}
}
</script><input name="button" type="button" class="button" value="检测" onClick="checkName(document.form1.type.value)" ></td>
test.asp
<!--#include file="conn.asp" -->
<%
dim strNewName
strNewName=request("uName")
set rs=server.createobject("adodb.recordset")
sql="select * from book where type='"&strNewName&"'"
rs.open sql,conn,1,3
if not(rs.eof and rs.bof) then
a1=rs("name")
response.write 0
else
response.write 1
end if
rs.close
set rs=nothing
%>
程序运行后,无论该名称是否存在,都会提示“对不起,你不能使用”这一行