2013-09-08 2 views
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'을도이 상점 양식 필드에있는 데이터입니다.

무엇이 잘못 되었나요?

답변

2

문제가 PHP 스크립트에 있습니다. PHP에서 문자열을 연결하려는 경우 . 점을 사용하십시오. +은 자바 스크립트와 같은 언어로 문자열을 연결하는 데 사용됩니다.

echo 'email = ' . $_POST["email"]; 
+0

와우 –

관련 문제