验证用户名是否可用例题

1.注册页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery-1.11.2.min.js" type="text/javascript"></script>/*要引入文件*/
</head>

<body>
<input type="text" id="uid" />
<span id="ts"></span>
</body>
<script type="text/javascript">
$("#uid").blur(function(){
    //取用户名
    var uid=$("#uid").val();
    //调用AJAX
    $.ajax({
            url:"uidchuli.php",
            data:{uid:uid},
            type:"POST",
            dataType:"TEXT",
            success: function(data){
                    if(data>0){
                        $("#ts").html("该用户名已存在");
                        $("#ts").css("color","red");
                        }else{
                                $("#ts").html("该用户名可用");
                                $("#ts").css("color","green");
                            }
                }
        });
});
</script>

 

</html>

2.处理页面

<?php
$uid=$_POST['uid'];
include("./lei/AAA.class.php");
$db=new AAA();
$sql="select count(*) from family where name='{$uid}' ";
 echo $db->StrQuery($sql);

?>

 

posted on 2016-11-11 15:22  向前看!明天会更好!  阅读(105)  评论(0编辑  收藏  举报