AJAX->[CODE:]
<script language="javascript" type="text/javascript">
var request = false;
try{
request = new XMLHttpRequest();
}catch (trymicrosoft){
try{
request = new ActiveXObject("Msxml2.XMLHTTP");
}catch (othermicrosoft){
try{
request = new ActiveXObject("Microsoft.XMLHTTP");
}catch (failed){
request = false;
}
}
}
if (!request)
alert("--------------------------------------\n 您 的浏览器不支持 XMLHttpRequest! \n ^_^ \n--------------------------------------\n");
function getUserName(){ //发送参数
var username = document.getElementById("users").value;
var url = "./ajax.php?username=" + username;
//alert(url);
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
function updatePage(){ //接收参数
if(request.readyState == 4){ //已完成
if(request.status == 200){
if(request.responseText == "false"){
document.getElementById("userid").innerHTML = "不存在";
}else if(request.responseText == "true"){
document.getElementById("userid").innerHTML = "已存在";
}
}else
alert("status is " + request.status);
}
}
"users" type="text" id="users" onBlur="getUserName();" />
?>
ajax.php->[CODE:]
if($_GET["username"] != ""){
require_once("./Conn_DB.php");
$link = new Conn_DB();
$arrays = $link -> Query("SELECT * FROM users WHERE users='".$_GET["username"]."'");
if(count($arrays) == 1){ //从数据库中取出已有项
echo "true";
}else{
echo "false";
}
}
?>