這裏是案件球員,我想檢查onblur事件的用戶名與ajax,這是檢查用戶名可用性在mysql數據庫的幫助。ajax檢查用戶名onblur
這裏是AJAX腳本=>
document.getElementById("r_username").onblur = function(){
var http = false;
var error = document.getElementById("error_username");
var numLetter = /^[a-zA-Z-0-9]+$/;
if (this.value==""){
error.innerHTML = "Empty Field !!!";
error.style.display = "inline";
} else {
if (this.value.match(numLetter)){
if (window.XMLHttpRequest){
http = new XMLHttpRequest();
} else {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
if (http){
http.open("POST","./config/AjaxUsernameEmail.php",true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function(){
if (http.readyState==4 && http.status==200){
}
};
http.send("r_username=" + document.getElementById("r_username").value);
}
error.innerHTML = "";
error.style.display = "none";
} else {
error.innerHTML = "Invalid Number !!!";
error.style.display = "inline";
}
}
};
阿賈克斯成功合作和PHP文件也該腳本如下=>
class Checking{
private $con,$query,$flag;
public function __construct($con,$query){
$this->con = $con;
$this->query = $query;
}
public function func(){
if (mysqli_connect_errno()==0){
if ($result = mysqli_query($this->con,$this->query)){
if ($data = mysqli_fetch_assoc($result)){
return $this->flag = true;
} else {
return $this->flag = false;
}
}
}
}
}
if (isset($_POST['r_username'])){
$check = new Checking($connection,"SELECT username FROM users WHERE username='" . $_POST['r_username'] . "'");
} else {
header("Location: http://" . $mysql->host . "/index.php");
}
一切工作正常,但這裏的問題,我想以某種方式連接這個文件,我的意思是我想在.js文件中知道當用戶名在數據庫中匹配,而不是時,因爲我想在.js文件中做更多的動作,但是我不能設置「標誌」 (變量會幫助我)。 任何想法?謝謝:)))
在更多的細節,.js文件是在registration.php文件中,以及如何看到球員.js文件正在調用AjaxUsernameEmail.php文件,所以我想做點什麼來知道什麼時候因爲我想在registration.php文件中做更多的動作(通知)匹配
這不是主要的問題,也這是工作沒有回聲和/或打印。我只測試過AjaxUsernameEmail.php文件,所以=>在提到的文件腳本中我已經將POST替換爲GET方法,並且在瀏覽器URL中輸入了.php?r_username =(名稱與mysql數據庫匹配)並且具有調用echo $ check-> func();是被調用的,並且如果它匹配的話給我寫1,如果它不匹配則不寫。在這裏,我的問題是,我想以某種方式在.js文件中知道這個匹配問題以執行更多操作 – tnanoba