一个注册时检测用户名是否存在的代码有关问题
一个注册时检测用户名是否存在的代码问题
JS代码如下:
<script language = "JavaScript ">
function checkName()
{
var NameStr=document.all.UserName.value
var xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP ");
xmlhttp.open( "POST ", "check_id.asp?uName= "+NameStr, false);
xmlhttp.send();
if(xmlhttp.ResponseText==1)
alert( "用户名已经存在! ");
else
alert( "可以使用! ");
}
check_id.asp的代码如下:
<!--#include file= "Conn.asp " -->
<%
Set RS = Server.CreateObject ( "ADODB.Recordset ")
SQL = "Select * from [Tb_UserInfo] where UserName= ' "&Request( "UserName ")& " ' "
RS.Open SQL,Conn,1,3
If Not RS.EOF and Not RS.BOF then
Response.write 1
Elseif RS.EOF and Not RS.BOF then
Response.write 0
End If
RS.close
%>
用户名这边是这么写的:
<input name= "UserName " type= "text " id= "UserName " size= "25 " maxlength= "255 ">
<font color= "#ff6600 "> * </font>
<input type= "button " value= "检测用户名 " onclick= "checkName() ">
表单的名字为myform
我查了好久,也没有查出问题,输入了一个已经存在的用户名可还是弹出可以注册,真是纳闷了,希望高手帮忙
------解决方案--------------------
自己要调试
撇开那个客户端不谈
你先直接运行check_id.asp?UserName=***
看看能不能response.write出来
分出是服务端问题还是客户端问题
然后再检查~
把错误贴出来 能解决的就多了~
学会问问题~
------解决方案--------------------
if(xmlhttp.ResponseText==1)
改成if(xmlhttp.ResponseText== "1 ")
Response.write 1
改成Response.write "1 "
试试
JS代码如下:
<script language = "JavaScript ">
function checkName()
{
var NameStr=document.all.UserName.value
var xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP ");
xmlhttp.open( "POST ", "check_id.asp?uName= "+NameStr, false);
xmlhttp.send();
if(xmlhttp.ResponseText==1)
alert( "用户名已经存在! ");
else
alert( "可以使用! ");
}
check_id.asp的代码如下:
<!--#include file= "Conn.asp " -->
<%
Set RS = Server.CreateObject ( "ADODB.Recordset ")
SQL = "Select * from [Tb_UserInfo] where UserName= ' "&Request( "UserName ")& " ' "
RS.Open SQL,Conn,1,3
If Not RS.EOF and Not RS.BOF then
Response.write 1
Elseif RS.EOF and Not RS.BOF then
Response.write 0
End If
RS.close
%>
用户名这边是这么写的:
<input name= "UserName " type= "text " id= "UserName " size= "25 " maxlength= "255 ">
<font color= "#ff6600 "> * </font>
<input type= "button " value= "检测用户名 " onclick= "checkName() ">
表单的名字为myform
我查了好久,也没有查出问题,输入了一个已经存在的用户名可还是弹出可以注册,真是纳闷了,希望高手帮忙
------解决方案--------------------
自己要调试
撇开那个客户端不谈
你先直接运行check_id.asp?UserName=***
看看能不能response.write出来
分出是服务端问题还是客户端问题
然后再检查~
把错误贴出来 能解决的就多了~
学会问问题~
------解决方案--------------------
if(xmlhttp.ResponseText==1)
改成if(xmlhttp.ResponseText== "1 ")
Response.write 1
改成Response.write "1 "
试试