简体   繁体   中英

User name availability check not connecting

I found a free script for username validation on the interwebs, This is the javascript side of it:

$(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:

<?

$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

When you type in "mike" in my website, it says that the username is available for use. 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? 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. 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进行获取

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM