实时检查帐号是否被注册
本例与《php jquery check username ajax检查帐号唯一性》功能差不多,表结构也是一样的
XML/HTML Code
- <div class="both">
- <h4> "John" , "eliane" </h4><br clear="all" /><br clear="all" />
- <br clear="all" />
- <div>
- <label>User Name</label>
- <input id="username" name="username" type="text" value="" onblur="return check_username();" />
- <div id="Info"></div>
- <span id="Loading"><img src="loader.gif" alt="" /></span>
- </div>
- </div>
JavaScript Code
- <script type="text/javascript">
- $(document).ready(function() {
- $('#Loading').hide();
- });
- function check_username(){
- var username = $("#username").val();
- if(username.length > 2){
- $('#Loading').show();
- $.post("check_username_availablity.php", {
- username: $('#username').val(),
- }, function(response){
- $('#Info').fadeOut();
- $('#Loading').hide();
- setTimeout("finishAjax('Info', '"+escape(response)+"')", 450);
- });
- return false;
- }
- }
- function finishAjax(id, response){
- $('#'+id).html(unescape(response));
- $('#'+id).fadeIn(1000);
- }
- </script>
check_username_availablity.php
PHP Code
- <?php
- include('../../conn.php');
- if($_REQUEST)
- {
- $username = $_REQUEST['username'];
- $query = "select * from username_list where username = '".strtolower($username)."'";
- $results = mysql_query( $query) or die('ok');
- if(mysql_num_rows(@$results) > 0) // not available
- {
- echo '<div id="Error">Already Taken</div>';
- }
- else
- {
- echo '<div id="Success">Available</div>';
- }
- }?>
原文地址:http://www.freejs.net/article_biaodan_302.html