今天用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>
<INPUT name=name class=from id="name"
style="WIDTH: 150px" maxLength=10 title="请用英文字母(a-z)或英文字母和数字的组合">
<span id="txt"> </span>
</TD>
</TR>
<TR>
<TD bgColor=#ffffff height=30>
<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 "该用户名没有被注册了,可以注册";