`

实时检查帐号是否被注册

 
阅读更多

实时检查帐号是否被注册

 本例与《php jquery check username ajax检查帐号唯一性》功能差不多,表结构也是一样的

实时检查帐号是否被注册
  •  
XML/HTML Code
  1. <div class="both">  
  2.         <h4> "John" , "eliane" </h4><br clear="all" /><br clear="all" />  
  3.         <br clear="all" />  
  4.         <div>  
  5.             <label>User Name</label>  
  6.             <input id="username" name="username" type="text" value="" onblur="return check_username();" />  
  7.             <div id="Info"></div>  
  8.             <span id="Loading"><img src="loader.gif" alt="" /></span>  
  9.         </div>  
  10.     </div>  

 

JavaScript Code
  1. <script type="text/javascript">  
  2.   
  3. $(document).ready(function() {  
  4.     $('#Loading').hide();      
  5. });  
  6.   
  7. function check_username(){  
  8.   
  9.     var username = $("#username").val();  
  10.     if(username.length > 2){  
  11.         $('#Loading').show();  
  12.         $.post("check_username_availablity.php", {  
  13.             username: $('#username').val(),  
  14.         }, function(response){  
  15.             $('#Info').fadeOut();  
  16.              $('#Loading').hide();  
  17.             setTimeout("finishAjax('Info', '"+escape(response)+"')", 450);  
  18.         });  
  19.         return false;  
  20.     }  
  21. }  
  22.   
  23. function finishAjax(id, response){  
  24.    
  25.   $('#'+id).html(unescape(response));  
  26.   $('#'+id).fadeIn(1000);  
  27. }   
  28.   
  29. </script>  

 check_username_availablity.php

 

PHP Code
  1. <?php  
  2. include('../../conn.php');  
  3. if($_REQUEST)  
  4. {  
  5.     $username   = $_REQUEST['username'];  
  6.     $query = "select * from username_list where username = '".strtolower($username)."'";  
  7.     $results = mysql_query( $queryor die('ok');  
  8.       
  9.     if(mysql_num_rows(@$results) > 0) // not available  
  10.     {  
  11.         echo '<div id="Error">Already Taken</div>';  
  12.     }  
  13.     else  
  14.     {  
  15.         echo '<div id="Success">Available</div>';  
  16.     }  
  17.       
  18. }?>  

 


原文地址:http://www.freejs.net/article_biaodan_302.html

0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics