posts - 12,  comments - 0,  trackbacks - 0
var xmlHttp;

function createXMLHttpRequest() {
    
if (window.ActiveXObject) {
        xmlHttp 
= new ActiveXObject("Microsoft.XMLHTTP");
    }
 else if (window.XMLHttpRequest) {
        xmlHttp 
= new XMLHttpRequest();
    }

}


function checkaccount() {
    
var account = document.register.account.value;
    
if(account.length < 5{
        document.getElementById(
"account01").innerHTML = "5~20字の半角英数字";
        
return false;
    }
 else {
        document.getElementById(
"account01").innerHTML = "";
    }

    createXMLHttpRequest();
    xmlHttp.onreadystatechange 
= handleAddStateChange;
    xmlHttp.open(
"POST""check.php"true);
    xmlHttp.setRequestHeader( 'Content
-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send(
"account="+document.register.account.value);
}


function handleAddStateChange() {
    
if(xmlHttp.readyState == 4{
        
if(xmlHttp.status == 200{
            
var responseText = xmlHttp.responseText;
            
if(responseText == "1"{
                document.getElementById(
"account01").innerHTML = "ユーザーの名重複する";
        
return false;
            }
 else {
        document.getElementById(
"account01").innerHTML = "";
            }

        }
 else {
            alert(
"Error.");
        }

    }

}

checkaccount.js

xmlHttp.open("POST", "check.php", true);这里的true为异步,flase为同步

<?php
include 'ChinaBS.php';

$chinabs = new ChinaBS();

$bs = $chinabs->queryAll($_POST['account']);
$status = "0";

if($bs != null) {
    
$status = "1";
else {
    
$status = "0";
}
echo $status;
?>
check.php

<input type="text" id="account" name="account" size="20" maxlength="20" tabindex="1" onblur="checkaccount()" />
        
<font color="red"><span id="account01"></span></font>
test.php
posted on 2008-07-22 08:53 Jarry 阅读(123) 评论(0)  编辑 收藏 引用 网摘 所属分类: Script

只有注册用户登录后才能发表评论。
网站导航: