tp架構的ajax驗證使用者姓名的比較

來源:互聯網
上載者:User

標籤:tp架構的ajax驗證使用者姓名的比較

資料庫設計隨意設計吧 反正就是使用者可以存入就可以了!

本文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" style="text-align:left; width:100%; border:0;">                                <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 style="width:13%; text-align: right;">                                        <label for="User_username" class="required">使用者名稱                                         </label>                                        </td>                                        <td style="width:87%;">                                            <input class="inputBg" size="25" name="User[username]" id="User_username" type="text" value=""  onblur = "checkname()"/>                                                              <span id="span1" class="msg"></span>                                        </td>                                    </tr>


本文出自 “kangjunfei” 部落格,轉載請與作者聯絡!

tp架構的ajax驗證使用者姓名的比較

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.