a.asp
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function doRequestUsingGET() {
createXMLHttpRequest();
var username=document.getElementById("username").value;
var queryString = "shi.asp?username="+encodeURIComponent(username);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET", queryString, true);
xmlHttp.send(null);
}
function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
var text=xmlHttp.responseText;
document.getElementById("users").innerText=text;
}
}
}
//下面的是密码
function doRequestUsingGET1() {
createXMLHttpRequest();
var pwd=document.getElementById("pwd").value;
var queryString = "shi.asp?pwd="+encodeURIComponent(pwd);
xmlHttp.onreadystatechange = handleStateChange1;
xmlHttp.open("GET", queryString, true);
xmlHttp.send(null);
}
function handleStateChange1() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
var text=xmlHttp.responseText;
document.getElementById("pwda").innerText=text;
}
}
}
</script>
<table>
<tbody>
<tr>
<td>First name:</td>
<td><input type="text" id="username" name="username" οnchange="doRequestUsingGET()"/></td>
<td><div id="users"></div>
</td>
</tr>
<tr>
<td>First name:</td>
<td><input type="text" id="pwd" name="pwd" οnchange="doRequestUsingGET1()"/></td>
<td><div id="pwda"></div>
</td>
</tr>
</tbody>
</table>
shi.asp
<!--#include file="conn.asp"-->
<!--#include file="md5.asp"-->
<%
Response.ContentType = "text/html"
Response.Charset = "GB2312" '设置数据流为gb2312,ajax传来的默认为uf8,会产生乱码
dim username
username=request("username")
pwd=md5(request("pwd"))
'response.write "user:"&username&""
'response.write "<br>"&pwd&""
if username<>"" then
set rs=server.CreateObject("adodb.recordset")
sql="select * from article_User where username='"&username&"'"
rs.open sql,conn,1,1
if not rs.eof and not rs.bof then
response.write "此用户名已被注册!"
else
response.write "此用户名可用!"
end if
else
set rs=server.CreateObject("adodb.recordset")
sql="select * from article_User where pwd='"&pwd&"'"
rs.open sql,conn,1,1
if not rs.eof and not rs.bof then
response.write "此密码已被设定!"
else
response.write "可以使用本密码!"
end if
end if
%>