簡體   English   中英

用戶名可用性檢查未連接

[英]User name availability check not connecting

我在interwebs上找到了一個用於用戶名驗證的免費腳本,這是它的javascript方面:

$(document).ready(function () {

    $("#username").blur(function () {
        $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
        //check the username exists or not from ajax
        $.post("availability.php", {
            user_name: $(this).val()
        }, function (data) {
            if (data == 'no') //if username not avaiable
            {
                $("#msgbox").fadeTo(200, 0.1, function () //start fading the messagebox
                {
                    $(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900, 1);
                });
            } else {
                $("#msgbox").fadeTo(200, 0.1, function () //start fading the messagebox
                {
                    $(this).html('Username available to register').addClass('messageboxok').fadeTo(900, 1);
                });
            }

        });    
    });

});

你看到這引用了“availibility.php”頁面,代碼如下:

<?

$existing_users=array('roshan','mike','jason'); 


$user_name=$_POST['user_name'];


if (in_array($user_name, $existing_users))

{


echo "no";

} 

else

{

//user name is available

echo "yes";

}

?>

最后,在頁面上,這是用戶輸入數據的輸入標記:

<input name="user_name" type="text" id="username" value="" maxlength="15" />
     <span id="msgbox" style="display:none"></span>

我有使用最新版本的jquery(1.4.4)的腳本,這是一個工作示例的鏈接鏈接

當您在我的網站中輸入“mike”時,它表示該用戶名可供使用。 在我上面提供的示例鏈接中,用戶名就像它應該的那樣。

我能想到的唯一可能的問題可能是我的主機不支持ajax? 思考?

謝謝!

檢查firebug,chrome等中的響應...無論你使用什么,我的猜測是"no"不是響應中唯一回應的東西,你可以在頂部做一個簡單的alert(data) $.post()成功處理程序的名稱,以查看其中可能還有其他內容。 確保響應中回顯您想要的內容。

這是php mysql jquery Ajax中用於用戶名可用性檢查器的最佳腳本,可從此處http://www.my-php-scripts.net/index.php/Jquery/ajax-username-availability.html進行獲取

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM