index.php //用于界面显示
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
<form action="" name="myform" method="post" enctype="text/plain">
username:
<input type="text" name="username" value="" οnblur="funphp100('php')"/>
<div id="php200" style="height:14px;"></div>
</form>
for.php //用于接收参数并处理
<?php
if($_GET[id]=='user')
{
echo '重名';
}
else
{
echo "dddddd";
}
?>
ajax.js //ajax技术处理
var xmlHttp;
function xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function funphp100(username){
var name=document.myform.username.value;
xmlhttprequest();
xmlHttp.open("POST","for.php?id="+name,true);
xmlHttp.onreadystatechange=byphp;
xmlHttp.send(null);
}
function byphp(){
var byphp100=xmlHttp.responseText;
if(xmlHttp.readyState==4)
{
if(xmlHttp.Status==200)
{
var byphp100=xmlHttp.responseText;
document.getElementById('php200').innerHTML=byphp100;
}
}
}
不解释的了,跟上两篇文章的原理相同