<html>
<head>
<title>異步表單驗證</title>
<script type='text/javascript' src='jquery.js' ></script>
<script>
function checkname(){
//$("input[name='name']").val()
$.ajax({
type:"get",
url:'index.php',
data:"name="+$("input[name='name']").val(),
success:function(msg){
$("#show").append(msg);
}
});}
</script>
</head>
<body>
<form name='form'>
<input name='name' type='text' onblur='checkname();'>
<span id='show'></span><br />
<input type='submit' name='submit' value='提交' />
</form>
</body>
</html>
php代碼:
代碼如下:
<?php
//進(jìn)行連接服務(wù)器
$link=mysql_connect('localhost','root','sanyue');
if(!$link){
die('連接失敗:'.mysql_error());
}
//進(jìn)行連接數(shù)據(jù)庫
mysql_select_db('excour',$link);// $name=$_GET['name'];
echo $name;
$sql="select name from user_info where name='$name'";//執(zhí)行查詢語句
$result=mysql_query($sql);
if(mysql_num_rows($result) != 0){
echo "<font color='red'>名字太受歡迎,換一個吧</font>";
}else{
echo "<font color='blue'>成功</font>";
}//進(jìn)行釋放查詢結(jié)果集
mysql_free_result($result);
//關(guān)閉數(shù)據(jù)庫連接
mysql_close($link);
?>
運行結(jié)果示例:![]()
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com