下面是我的html,我需要沒有表單格式的輸入對話框。Ajax php驗證沒有功能
<!DOCTYPE>
<html>
<head>
<script>
var username;
function myFunction() {
//input dialog
username = prompt("Please enter your name", "");
if (username != "") {
checkNameValidate();
} else {
alert("The name is empty, please insert your name");
}
}
function checkName() { //ajax to validate.php
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "validate.php?username=" + username, false);
xmlhttp.send(null);
//doFunction();
}
function doFunction() {
//function
}
</script>
</head>
<body>
<input type="button" onclick="myFunction()" value="Name" />
</body>
</html>
下面
是validate.php代碼,我的數據庫名是testajax,
<?php
$username=$_POST["username"];
mysql_connect("localhost","root","");
mysql_select_db("testajax");
$query1 = mysql_query("select * from user where name='$username'");
if(mysql_num_rows($query1)>0){
echo "<script language=javascript>alert('The name have used');</script>";
}
?>
這是我的工作,但無法驗證用戶,什麼是我的錯,任何人都可以幫助矯正?
但無法驗證用戶不足以理解發生了什麼。你能解釋一下你的期望和做什麼? – Saif