请高手帮帮忙,在线等
<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
%>
程序运行后,无论该名称是否存在,都会提示“对不起,你不能使用”这一行 xmlhttp.send();
//加一个两个条件
if(xmlhttp.getHttpRequest().readyState==4)
{
if (xmlhttp.getHttpRequest().status==200)
{
var rs=xmlhttp.getHttpRequest().responseText;
//用alert()弹出来是返回什么东西
alert(rs);
//再看看你这里呆会将弹出什么
alert(rs==0?"已经存在相同的用户名"
:"对不起,你不能使用");
}else{
alert("页面不存在或出现异常......");
}
} 按楼主所说,改了一下,提示“对象不支持此属性”,再次郁闷中。。。。
这行:if(xmlhttp.getHttpRequest().readyState==4)
页:
[1]
