AJAX应用之注册用户检测
<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) {
test1.innerHTML="正在检测";
}
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
test1.innerHTML=response;
}
if (test1.innerHTML=="已被注册"){
document.form1.submit.disabled=true}else{
document.form1.submit.disabled=false
}
}
</script>
<form name="form1" action="t1.asp" method="post" autocomplete="off">
用户名: <input type="text" name="u_name" id="u_name" onChange="callServer();" />
<span id="test1">是否能注册</span><br>
密 码:<input type="password" />
<input type="submit" name="submit" value="注册" />
</form>
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) {
test1.innerHTML="正在检测";
}
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
test1.innerHTML=response;
}
if (test1.innerHTML=="已被注册"){
document.form1.submit.disabled=true}else{
document.form1.submit.disabled=false
}
}
</script>
<form name="form1" action="t1.asp" method="post" autocomplete="off">
用户名: <input type="text" name="u_name" id="u_name" onChange="callServer();" />
<span id="test1">是否能注册</span><br>
密 码:<input type="password" />
<input type="submit" name="submit" value="注册" />
</form>
申明
非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!
博文欢迎转载,但请给出原文连接。