Ò»¡¢zhuce.php
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Óû§×¢²á</title>
<script type="text/javascript">
//´´½¨ajaxÒýÇæ
function getXmlHttpObject(){
//²»Í¬µÄä¯ÀÀÆ÷»ñÈ¡xmlhttprequest µÄ·½·¨²»Ò»Ñù
if(window.ActiveXObject){
//window.alert('ie');
xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}
else{
//window.alert('ff');
xmlHttpRequest=new XMLHttpRequest();
}
return xmlHttpRequest;
}
var myXmlHttpRequest="";
function checkName(){
myXmlHttpRequest=getXmlHttpObject();//1ºÅÏß
if(myXmlHttpRequest){
//window.alert("´´½¨AjaxÒýÇæ³É¹¦£¡");
//ͨ¹ýmyXmlHttpRequest¶ÔÏó·¢ËÍÇëÇóµ½·þÎñÆ÷µÄijһ¸öÒ³Ãæ
//µÚÒ»¸ö²ÎÊý±íʾÇëÇóµÄ·½Ê½£¬get/post
//µÚ¶þ¸ö²ÎÊýÖ¸¶¨url£¬¶ÔÄǸöÒ³Ãæ·¢³öajaxÇëÇó(±¾ÖÊÈÔÈ»ÊÇhttpÇëÇó)£¬Ö»ÒªÊÇweb¿ª·¢µÄµ×²ãÊÇhttpÇëÇó£¬httpµÄµ×²ãÊÇtcp/ipÐÒé
//µÚÈý¸ö²ÎÊý true ±íʹÓÃÒì²½»úÖÆ£¬false±íʾ²»Ê¹ÓÃÒì²½»úÖÆ¡£
//´ò¿ªÇëÇó
//var url="/ajax/registerPro.php?username="+$("username").value;
//var url="/ajax/registerPro.php?mytime="+new date()+"&username="+$("username").value;
var url="registerPro.php";
//Õâ¸öÊÇÒª·¢ËÍÊý¾Ý
var data="username="+$("username").value;
//window.alert(url);
myXmlHttpRequest.open("post",url,true);
//Õâ¾ä»°²»¿ÉÉÙ
//http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//Ö¸¶¨»Øµ÷º¯Êý . chuliÊǺ¯ÊýÃû
myXmlHttpRequest.onreadystatechange=chuli;
//ÕæµÄ·¢ËÍÇëÇó£¬Èç¹ûÊÇgetÇëÇó·¢ËÍnull¼´¿É£»Èç¹ûÊÇpostÇëÇó£¬ÔòÌîÈëʵ¼ÊµÄÇëÇó¼´¿É
//myXmlHttpRequest.send(null); //2ºÅÏß
myXmlHttpRequest.send(data); //2ºÅÏß
}
}
//»Øµ÷º¯Êý
function chuli(){
}
//ÕâÀïдһ¸öº¯Êý
function $(id){
return document.getElementById(id);
}
</script>
</head>
<body>
<form action="" method="post">
Óû§Ãû×Ö1£º<input type="text" onblur="checkName()" name="username1" id="username" />
Óû§Ãû×Ö£º<input type="text" onkeyup="checkName()" name="username2" id="username" />
<input onclick="checkName();" type="button" value="ÑéÖ¤Óû§Ãû" /><input style="border-width:0px;color:red;" type="text" id="myres"/> <br />
Óû§ÃÜÂ룺<input type="password" name="password" /> <br />
µç×ÓÓʼþ£º<input type="text" name="email" /> <br /> <input type="button" value="×¢²áÕ˺Å">
</form>
</body>
</html>
¶þ¡¢registerPro.php
<?php
$username = $_POST['username'];
// echo "Óû§ÃûÊÇ£º" . $username; // 3ºÅÏß
if ($username == "zhosoft") {
echo "´ËÓû§Ãû²»¿ÉÓã¡"; // ×¢Ò⣬ÕâÀïµÄÊý¾ÝÊÇ·µ»Ø¸øÇëÇóµÄÒ³Ãæ¡£
} else {
echo "¹§Ï²Äú£¬´ËÓû§Ãû¿ÉÓã¡";
}
?>
¡¡