これがケースです。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";
}
}
};
ajaxが正常に動作し、スクリプトが以下の.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ファイルがajax AjaxUsernameEmail.phpファイルで呼び出しているのを見ることができるので、どうにかしてユーザー名が一致するときと一致しないときを知りたいので、 registration.php ファイルで、マッチング中にさらにアクション (通知) を実行したい