0
로그인 양식에 입력 한 값 (이메일 및 비밀번호)이 내 서버 PHP 스크립트로 구문 분석되지 않는 문제가 있습니다.ajax 요청이 양식 데이터를 게시하지 않습니다.
내 아약스 요청 :
function signin(){
var loginEmail = gebi("loginEmail").value;
var loginPass = gebi("loginPass").value;
if(loginEmail == "" || loginPass == ""){
gebi("loginEmail").style.borderColor = "red";
gebi("loginPass").style.borderColor = "red";
} else {
gebi("signinBtn").style.display = "none";
//Declare ajax request variables
hr = new XMLHttpRequest();
url = "main.php";
vars = "email="+loginEmail+"&pass="+loginPass;
//Open the PHP file that is receiving the request
hr.open("POST", url, true);
//Set content type header info for sending url ecncoded variable in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//Trim string data before sending it
if (!String.prototype.trim) {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
};
}
//Access the onreadystatechange event for the XMLHttpRequest
hr.onreadystatechange = function() {
if (hr.readyState == 4 && hr.status == 200) {
var responseText = hr.responseText.trim();
if (responseText != "signin_failed") {
console.log(responseText);
} else {
console.log(responseText);
gebi("signinBtn").style.display = "block";
gebi("loginEmail").style.borderColor = "red";
gebi("loginPass").style.borderColor = "red";
}
}
}
//Send the data to the PHP file for processing and wait for responseText
hr.send(vars);
}
}
와 PHP 스크립트는이 코드를 사용하여 값을 반환 할 때 :
if (isset($_POST["email"])) {
echo 'email = '+$_POST["email"];
}
콘솔에 기록됩니다 반환 값이 '0'을도이 상점 양식 필드에있는 데이터입니다.
무엇이 잘못 되었나요?
와우 –