<script language="JavaScript">
<!--
function check_User() {
var xmlHttp = false;
try {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) {try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e2) {xmlHttp = false;}}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {xmlHttp = new XMLHttpRequest();}
if (document.form1.User.value!="") {
var User = document.form1.User.value;
xmlHttp.open("GET","reg_detectname.asp?a=b&name="+escape(User),false);
xmlHttp.send(null);
document.getElementById('a1').innerHTML = xmlHttp.responseText;
document.form1.submit.disabled = false;
} else {
document.getElementById('a1').innerHTML = "<font color=red>名字不能为空</font>";
document.a1.submit.disabled = true;
return true;
}
}
//-->
</script>
<form name="form1" action="Reg_save.asp" method="POST">
<input name="User" type="text" onkeyup="check_User();" /> <span id="a1"></span>
</form>
reg_detectname.asp
<!--#include file="conn.asp"-->
<%
if request("a")="b" then
User=request("name")
set rs=server.createobject("adodb.recordset")
rs.open "select * from UserMain where User='"&User&"'",conn,1,1
if rs.bof and rs.eof then
response.write "<font color=green>可以注册 !</font>"
else
response.write "<font color=red>不可以注册 !</font>"
end if
rs.close
set rs=nothing
end if
%>
我就改了CONN.ASP和SQL语句怎么CS时不提示是否能注册。我用的是SQLserver请各位大虾再帮忙看看是那有问题
<script language="JavaScript">
<!--
function check_User() {
var xmlHttp = false;
try {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) {try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e2) {xmlHttp = false;}}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {xmlHttp = new XMLHttpRequest();}
if (document.form1.User.value!="") {
var User = document.form1.User.value;
xmlHttp.open("GET","reg_detectname.asp?a=b&name="+escape(User),false);
xmlHttp.send(null);
document.getElementById('a1').innerHTML = xmlHttp.responseText;
document.form1.submit.disabled = false;
} else {
document.getElementById('a1').innerHTML = "<font color=red>名字不能为空</font>";
document.a1.submit.disabled = true;
return true;
}
}
//-->
</script>
<form name="form1" action="Reg_save.asp" method="POST">
<input name="User" type="text" onkeyup="check_User();" /> <span zy="a1"></span>
</form>
reg_detectname.asp
<!--#include file="../db_conn/dhconn.asp"-->
<%
if request("a")="b" then
User=request("name")
set rs=server.createobject("adodb.recordset")
rs.open "select * from zy where zy='"&User&"'",conn,1,1
if rs.bof and rs.eof then
response.write "<font color=green>可以注册 !</font>"
else
response.write "<font color=red>不可以注册 !</font>"
end if
rs.close
set rs=nothing
end if
%>
[此贴子已经被作者于2007-9-21 12:04:37编辑过]
数据库路径问题,建议你直接把连接数据库代码放到reg_detectname.asp 文件里
不调用 <!--#include file="../db_conn/dhconn.asp"-->
reg_detectname.asp
<!--#include file="../db_conn/dhconn.asp"-->
<%
Response.ContentType = "text/html;charset=GB2312" '加上这段代码
if request("a")="b" then
User=request("name")
set rs=server.createobject("adodb.recordset")
rs.open "select * from zy where zy='"&User&"'",conn,1,1
if rs.bof and rs.eof then
response.write "<font color=green>可以注册 !</font>"
else
response.write "<font color=red>不可以注册 !</font>"
end if
rs.close
set rs=nothing
end if
%>
会不会是你的数据库链接方式不对,我没用过sql server,下面的方式楼主可以做个参考
'SQL OleDB 连接
'Connstr = "Driver={SQL Server}; Server=("&SqlLocalName&"); User ID="&SqlUserName&"; Password="&SqlPassWord&"; database="&SqlDatabaseName&";"
'SQL 连接
On Error Resume Next
Set Conn = Server.CreateObject("ADODB.CONNECTION")
Conn.Open Connstr
If Err.Number<>0 Then
Err.Clear
Set Conn = Nothing
Response.Write("<b style='font-size:16px'>数据库连接出错,请检查连接字串!")
Response.End()
End If
End Sub
Sub CloseDatabase
If IsObject(Conn) then
Conn.Close
Set Conn = Nothing
End if
End Sub