简单的AJAX技术

 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
%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值