温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

tp框架的ajax验证用户姓名的比较

发布时间:2020-09-18 22:08:01 来源:网络 阅读:541 作者:kangjunfei 栏目:系统运维

数据库设计随意设计吧 反正就是用户可以存入就可以了!

正文tp后台方法简化:

 //用户验证
   function checknm($name){
       $info = D('user')->where("user_name ='$name'")->find();
       //dump($info);die;
       $flag = '';
       if($info){
          echo 1;
         
       }else{
          echo 2;
        
       }
   }

后台返回1和2

前端ajax部分 用data接收1和2的状态

当然data的接收 主要看你后台传的是什么格式的数据类型了!这个大家可以百度ajax了!

<div class="usBox">
                    <div class="usBox_2 clearfix">
                        <div class="logtitle3"></div>
                        <form id="yw0" action="" method="post">
                        <style>
                         .msg{color:gray;}
                         .msg2{color:#ff3333;}
                        </style>
                         <table cellpadding="5" cellspacing="3" >
                                <tbody>
                                <script type="text/javascript" src="__PUBLIC__/js/jquery-1.8.3.min.js"></script>
                                 <script type="text/javascript">
                            
                                   function checkname(){
                                        var name = document.getElementById('User_username').value;
                                    
                                        $.get('/tpTest/index.php/User/checknm',{name:name},function(data){
                                            //alert(name);
                                         if(data == 1){
                                           var nm = document.getElementById('span1');
                                           nm.innerHTML='用户名存在';
                                           nm.className ="msg2";
                                         }
                                         if(data == 2){
                                         var nm = document.getElementById('span1');
                                           nm.innerHTML='用户可以使用';
                                           nm.className ="msg";
                                         
                                         }
                                        })
                            
                                   }
                                       
                                 </script>
                                    <tr>
                                        <td >
                                        <label for="User_username" class="required">用户名 
                                        </label>
                                        </td>
                                        <td >
                                            <input class="inputBg" size="25" name="User[username]" id="User_username" type="text" value=""  onblur = "checkname()"/>                  
                                            <span id="span1" class="msg"></span>
                                        </td>
                                    </tr>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI