第一个ajax程序,我的第一个AJAX程序

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

如下图~~

reg.jpg

程序代码如下~~

Reg.htm

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.');

}

}

}

  

maxLength=10 title="请用英文字母(a-z)或英文字母和数字的组合">

  

type=password maxLength=15 name=password onFocus="makeRequest('p','check_user.php?sub='+document.f.name.value);">

密码由 6-20 个英文字母或数字组成

'check_user.php

header('Content-type: text/html;charset=GBK');if ($isreg)echo "该用户名已经被注册,请选择个新的用户名";elseecho "该用户名没有被注册了,可以注册";

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值