doublestar2014 2010-12-13 00:08
浏览 55
已采纳

用户名可用性检查未连接

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!

  • 写回答

2条回答 默认 最新

  • dongzhouji4021 2010-12-13 00:12
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取