首页 > 代码库 > jquery json 判断用户是否已注册

jquery json 判断用户是否已注册

check_user.php

<?php 
	$link=mysqli_connect(‘localhost‘,‘root‘,‘root‘,‘test‘);//连接数据库
	if(mysqli_connect_errno()){
        echo mysqli_connect_error();
	}
 
            $query="select * from username where username=‘{$_GET[‘username‘]}‘";
            $result=mysqli_query($link,$query);
            $data=http://www.mamicode.com/mysqli_fetch_assoc($result);>

 index.php

<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script type="text/javascript" src="http://www.mamicode.com/js/jquery.min.js"></script>
	<script type="text/javascript" src="http://www.mamicode.com/js/index.js"></script>
</head>
<body>
	<input type="text" id="namevalue"><span class="error"></span>
	<br>
	<button id="btn">Send</button>
	结果:<span id="result"></span>
</body>
</html>

index.js

$(function(){
    $("#namevalue").blur(function(){
        $.get("/jquery/check_user.php",{
            username:$("#namevalue").val()
        },function(data,status){
            if(data!=null){
                $("#result").text("");
                $(".error").text("用户名已注册");
            }else{
                $(".error").text("");
                $("#result").text($("#namevalue").val());
            }
    },"json");
    });
});

 

jquery json 判断用户是否已注册