我的第一个AJAX程序

今天用AJAX写个是注册验证的程序,和ALIBAB网站用户注册的一样~~可以查看要注册的用户名是否被注册~~
如下图~~

演示地址:http://www.xhswzg.com/member/reg.php

程序代码如下~~

Reg.htm

  <script>
 var http_request = false;
        var object;
    function makeRequest(mark,url) {

        http_request = false;
                object =  document.getElementById(mark);
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/html');
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = alertContents;
        http_request.open('POST', url, true);
        http_request.send(null);

    }

    function alertContents() {
               
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                        var temp = http_request.responseText;
                        //var m = 'document.all.'+mark;
                        txt.innerHTML=http_request.responseText;
                //alert(http_request.responseText);
            } else {
                alert('There was a problem with the request.');
            }
        }

    }
</script> <TD bgColor=#ffffff height=30>&nbsp;&nbsp;
                                <INPUT name=name class=from id="name"
            style="WIDTH: 150px" maxLength=10 title="请用英文字母(a-z)或英文字母和数字的组合">
                              &nbsp;<span  id="txt">  </span>
         </TD>
                          </TR>
                          <TR>
                            <TD bgColor=#ffffff height=30>&nbsp;&nbsp;
                                <INPUT class=from
            style="WIDTH: 150px" type=password maxLength=15 name=password onFocus="makeRequest('p','check_user.php?sub='+document.f.name.value);">
                              密码由 6-20 个英文字母或数字组成</TD>
                          </TR>

'check_user.php

header('Content-type: text/html;charset=GBK');
if ($isreg)
echo "<FONT style='BACKGROUND-COLOR: yellow' color='red'>该用户名已经被注册,请选择个新的用户名</font>";
else
echo "该用户名没有被注册了,可以注册";

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值