简体   繁体   English

用户名可用性检查未连接

[英]User name availability check not connecting

I found a free script for username validation on the interwebs, This is the javascript side of it: 我在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);
                });
            }

        });    
    });

});

You see this references the page "availibility.php" that code is as follows: 你看到这引用了“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";

}

?>

And then finally, on the page, this is the input tag that the user enters data in: 最后,在页面上,这是用户输入数据的输入标记:

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

I have this script using the latest version of jquery (1.4.4) this is the link to a working example: Link 我有使用最新版本的jquery(1.4.4)的脚本,这是一个工作示例的链接链接

When you type in "mike" in my website, it says that the username is available for use. 当您在我的网站中输入“mike”时,它表示该用户名可供使用。 In the example link I provided above, the username is taken, like it should be. 在我上面提供的示例链接中,用户名就像它应该的那样。

The only possible issue I can think of is maybe my host does not provide support for ajax? 我能想到的唯一可能的问题可能是我的主机不支持ajax? Thoughts? 思考?

Thanks! 谢谢!

Check the response in firebug, chrome, etc...whatever you're using, my guess would be that "no" isn't the only thing being echoed in the response, you can do a simple alert(data) at the top of your success handler in $.post() to see what else may be in there. 检查firebug,chrome等中的响应...无论你使用什么,我的猜测是"no"不是响应中唯一回应的东西,你可以在顶部做一个简单的alert(data) $.post()成功处理程序的名称,以查看其中可能还有其他内容。 Make sure only what you want is echoed in the response. 确保响应中回显您想要的内容。

这是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