<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="../jquery-1.11.2.min.js"></script> <title>无标题文档</title> </head> <body> <input type="text" id="uid"/> <span id="ts"></span> </body> <script type="text/javascript"> $("#uid").blur(function(){ var uid=$("#uid").val(); $.ajax({ url:"uidchuli.php", data:{n:uid}, type:"POST", dataType:"TEXT", success:function(data){ if(data>0) { $("#ts").html("该用户已存在"); $("#ts").css("color","red") } else { $("#ts").html("该用户名可用"); $("#ts").css("color","green"); } } }) }) </script> </html>
<?php $uid=$_POST["n"]; include("../DBDA.class.php"); $db=new DBDA(); $sql="select count(*) from info where Name = '{$uid}'"; echo $db->StrQuery($sql);