ajax代码:
==========================================================================================================
ajax.js
var xmlHttp;
function creatXMLHttpRequest() {
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function startRequest(id,url) {
creatXMLHttpRequest();
xmlHttp.onreadystatechange = function(){handleStateChange(id);}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function handleStateChange(id) {
if(xmlHttp.readyState == 1) {
document.getElementById(id).innerHTML = "<div class='cs'>正在加载请稍等...</div>";
}
if(xmlHttp.readyState == 4 ){
if(xmlHttp.status == 200) {
var allcon =  xmlHttp.responseText;
document.getElementById(id).innerHTML = allcon;
//alert(allcon);
}
}
}php代码:
==========================================================================================================
<?php 
require_once('include/conn.php');
header('Content-Type:text/html;charset=GBK');
 if($_GET['name']!=''){
 $uname=$_GET['name'];
   sleep(1);
$strsql="SELECT * FROM tb_user WHERE userMobile='$uname'";
        $result=mssql_query($strsql);
        $rows=@mssql_num_rows($result);
        if($rows>0){
            echo "<font color=red>"."已被注册!"."</font>";
        }else{
            echo "<font color=red>"."此用户名未被注册!"."</font>";
        }
 }else{
 echo "<font color=red>"."用户不能为空且为手机号"."</font>";
 }
?>html页面代码:
==========================================================================================================
<input name="userMobile" type="text" id="userMobile" maxlength="11" onblur="startRequest('ajaxcls','eee.php?name='+this.value);"/></td>