开发者

User name availability check not connecting

开发者 https://www.devze.com 2023-01-30 00:28 出处:网络
I found a free script for username validation on the interwebs, This is the javascript side of it: $(document).ready(function () {

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').f开发者_开发百科adeTo(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.


Here is best script for username availability checker in php mysql jquery Ajax get it from here http://www.my-php-scripts.net/index.php/Jquery/ajax-username-availability.html

0

精彩评论

暂无评论...
验证码 换一张
取 消