唯一用户名jquery和PHP代码

$(document).ready(function(){
      $("#name").focus();//获得焦点
      $("#name").blur(function(){//失去焦点
        var name=$("#name").val();
        if (name) {
          $.post("onename.php",{'name':name},function(data){
            alert(data);
          });
        }else{
            alert("用户名不能为空");
        }
      });
    });

          //jquery代码

<?php
 header( 'Content-Type:text/html;charset=utf-8 ');
 include_once("conn/conn.php");
 $name=$_POST["name"];
 $sql="select * from user where name='$name'";
 $r=mysqli_query($link,$sql);
 $n=mysqli_num_rows($r);
 if($n>0){
  echo "用户名已被注册";
 }else{
  echo "用户名可以使用";
 }
?>

        //PHP代码  

原文地址:https://www.cnblogs.com/index0629/p/7885354.html