ajax加asp 自动检测用户名是否已被注册

<script language="javascript" type="text/javascript">
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();
}

function callServer() {
  var u_name = document.getElementById("u_name").value;
  if ((u_name == null) || (u_name == "")) return;
  var url = "cu.asp?name=" + escape(u_name);
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updatePage;
  xmlHttp.send(null); 
}

function updatePage() {
  if (xmlHttp.readyState < 4) {
 emailts.innerHTML="系统将自动检测您的用户名是否已被注册,请稍候...";
  }
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
  if (response=="true"){
   emailts.innerHTML='恭喜你,用户名还未被注册!';
   emailts.className="showok";   
  }
  else{
  emailts.innerHTML='对不起,用户名已被注册!';
  emailts.className="showno";
  }  
  }
}
</script>
<style type="text/css">
<!--
.showno {
 color: #FF0000;
 font-weight: bold;
 background:url("note_error.gif") no-repeat 12px center;
 padding-left:35px;
 
}
.showok {
 color: #FF0000;
 font-weight: bold;
 background:url("note_ok.gif") no-repeat 12px center;
 padding-left:35px;
 
}
-->
</style>
</head>

<body>
<table cellspacing="0" cellpadding="0" width="694" border="0">
  <tbody>
    <tr>
      <td width="179" height="40" align="right" class="F14">用户名:</td>
      <td width="168"><input id="u_name"  onChange="callServer();"  style="WIDTH: 155px" />
    </td>
      <td width="347"> <div id="emailts"></div></td>
    </tr>
    <tr>
      <td height="40" align="right" class="F14">Email地址:</td>
      <td colspan="2"><input id="email"   style="WIDTH: 155px" />     </td>
    </tr> 
  </tbody>
</table>

 

 

 

cu.asp

<%
Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "No-Cache"
%>
<!--#include file="conn.asp"-->
<%
name=request.querystring("name")
Set rs = Server.CreateObject ("ADODB.Recordset")
sql = "Select * from u_ser where u_name='"&name&"'"
rs.Open sql,conn,1,1
if rs.eof and rs.bof then
 response.write("true")
else
 response.write("false")
end if
rs.close
set rs=nothing
call CloseDatabase
%>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值