注册 登录
编程论坛 ASP技术论坛

检测用户名是否存在的问题

liu_libra 发布于 2008-10-25 14:08, 1197 次点击
用户前台
<td width="18%" height="20" align="right" bgcolor="#EEF7FF" class="STYLE4"><span class="STYLE1"> <span class="STYLE6">*</span> </span> 用 户 名:</td>
<td width="34%" align="left" bgcolor="#FFFFFF"><input name="username" type="text" id="username" maxlength="20" />
   <input type="button" name="Submit4" value="检测用户名" onClick="checkName()"></td>

checkName()代码:
<script language="javascript">
function checkName()
{
var NameStr=document.all.userame.value
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST", "UserCheckReg.asp?uName="+NameStr, false);
xmlhttp.send();
if(xmlhttp.ResponseText==1)
alert("用户名已经存在");
else
alert("可以使用!");
}
</script>


UserCheckReg.asp代码:
<script language="javascript">
function checkName()
{
var NameStr=document.all.userame.value
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST", "UserCheckReg.asp?uName="+NameStr, false);
xmlhttp.send();
if(xmlhttp.ResponseText==1)
alert("用户名已经存在");
else
alert("可以使用!");
}
</script>


在网上看到很多类似的代码,可放到我的程序里当点击“检查用户名”的按钮时一点反应也没有,各位帮我看看怎么回事?
4 回复
#2
liu_libra2008-10-25 14:10
刚复制错了,重发一次问题
检测用户名是否存在的问题
用户前台
<td width="18%" height="20" align="right" bgcolor="#EEF7FF" class="STYLE4"><span class="STYLE1"> <span class="STYLE6">*</span> </span> 用 户 名:</td>
<td width="34%" align="left" bgcolor="#FFFFFF"><input name="username" type="text" id="username" maxlength="20" />
   <input type="button" name="Submit4" value="检测用户名" onClick="checkName()"></td>

checkName()代码:
<script language="javascript">
function checkName()
{
var NameStr=document.all.userame.value
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST", "UserCheckReg.asp?uName="+NameStr, false);
xmlhttp.send();
if(xmlhttp.ResponseText==1)
alert("用户名已经存在");
else
alert("可以使用!");
}
</script>


UserCheckReg.asp代码:
<!--#include file="conn.asp"-->
<%
set rs=server.CreateObject("adodb.recordset")
strsql="select * from users where username='"&request("uName")&"'"

rs.open strsql,conn,1,1
if rs.eof and rs.bof  then
response.write 0
else
response.write 1
end if
rs.close
set rs=nothing
%>
在网上看到很多类似的代码,可放到我的程序里当点击“检查用户名”的按钮时一点反应也没有,各位帮我看看怎么回事?
#3
hmhz2008-10-25 17:27
程序代码:

checkName()代码:
<script language="javascript">
function $(id){return document.getElementById(id);}
function checkName(){
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.open("GET", "UserCheckReg.asp?uName="+escape($("userame").value),true);
    xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState==4 && xmlhttp.status==200){alert(xmlhttp.responseText);}
    }
    xmlhttp.send(null);
}
</script>


UserCheckReg.asp代码:
<!--#include file="conn.asp"-->
<%
Response.ContentType = "text/html;charset=GB2312"
Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"

if conn.execute("select count(*) from users where username='"&request("uName")&"'")(0)<>0 then
    response.write "用户名 “"&request("uName")&"”已存在!"
else
    response.write "用户名 “"&request("uName")&"” 可以注册!"
end if
%>
#4
liu_libra2008-10-26 01:14
谢谢楼上版主支持,可怎么还是没反应啊,唉,有个错误提示也好啊!
#5
hmhz2008-10-26 08:09
程序代码:

checkName()代码:
<script language="javascript">
function $(id){return document.getElementById(id);}
function checkName(){
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.open("GET","UserCheckReg.asp?uName="+escape($("userame").value),false);
    xmlhttp.send(null);
    alert(xmlhttp.responseText);
}
</script>


UserCheckReg.asp代码:
<!--#include file="conn.asp"-->
<%
Response.ContentType = "text/html;charset=GB2312"
Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"

if conn.execute("select count(*) from users where username='"&request("uName")&"'")(0)<>0 then
    response.write "用户名 “"&request("uName")&"”已存在!"
else
    response.write "用户名 “"&request("uName")&"” 可以注册!"
end if
%>
1