国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > AJAX > 正文

AJAX 用戶唯一性驗證實現(xiàn)代碼

2024-09-01 08:31:34
字體:
供稿:網(wǎng)友
用ajax實現(xiàn)用戶名的檢測,提示是否重復的實現(xiàn)代碼。

從數(shù)據(jù)庫my中的username用戶表里驗證:
checkusername.html:

復制代碼 代碼如下:


<!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=gb2312" />
<title>無標題文檔</title>
</head>
<script language="javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function send_request(url,data){
createXMLHttpRequest();
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange = check_lll;
xmlHttp.setRequestHeader("CONTENT-TYPE", "application/x-www-form-urlencoded");
xmlHttp.send("username=" + data);
}
function check_lll(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
alert(xmlHttp.responseText);
}
}
}
function check_username(){
var f = document.form1;
var username = f.username.value;
if(username == ""){
alert("NULL");
return false;
}
else{
send_request("check_it.php",username);
}
}
</script>
<body>
<form method="post" action="">
<p> </p><p>
姓名: <input type="text" />
</p>
<input type="button" value="check it" />
<p> </p>
<p> </p>
</form>
</body>
</html>


check_it.php:

復制代碼 代碼如下:


<?php
$username = $_POST["username"];
$conn = mysql_connect("localhost:3306","root","123");
mysql_select_db("my",$conn);
$sql = "select * from username where username = '$username'";
$result = mysql_query($sql,$conn);
$num = mysql_fetch_array($result);
if($num > 0){
printf("can't use");
}
else{
printf("It can use");
}


?>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 柏乡县| 如皋市| 崇明县| 固阳县| 永宁县| 衡山县| 义乌市| 神木县| 西乌珠穆沁旗| 昌邑市| 陆川县| 额敏县| 肥西县| 冷水江市| 盐池县| 西青区| 和政县| 昭通市| 浏阳市| 桓台县| 临汾市| 沙坪坝区| 宜昌市| 杭锦旗| 舟山市| 克山县| 皋兰县| 庆云县| 泽库县| 长海县| 临猗县| 禹州市| 秦安县| 波密县| 特克斯县| 凉城县| 东方市| 西藏| 盘山县| 河曲县| 延安市|