2013-03-20 3 views
0

내 이유는 무엇입니까? 내 PHP에서 오는 내 ajax.responseTest는 아래 자바 스크립트 조건부 코드에서 올바르게 평가되지 않습니다. ajax.responseTest는 "signup_success"로 돌아오고 있습니다. (경고 상자를 통해 확인해 보았지만 정확히 다시 돌아옵니다) JS 코드의 조건부가 올바르게 평가되지 않습니다. 여기 AJAX PHP 조건부 논리가 올바로 평가되지 않습니다.

는 자바 스크립트입니다 :

else { 
    _("signupbtn").style.display = "none"; 
    status.innerHTML = 'please wait ...'; 
    var ajax = ajaxObj("POST", "signup.php"); 
    ajax.onreadystatechange = function() { 
     if(ajaxReturn(ajax) == true) { 
      if(ajax.responseText != "signup_success"){ 
       status.innerHTML = ajax.responseText; 
       _("signupbtn").style.display = "block"; 
      } else { 
       _("sign").innerHTML = ajax.responseText; 
       window.scrollTo(0,0); 
       _("signupform").innerHTML = "OK "+u+", check your email inbox and junk mail box at <strong>"+e+"</strong> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account."; 
      } 
     } 
    } 
ajax.send("u="+u+"&e="+e+"&p="+p1+"&g="+g); 
} 

나는 == "는 다른 블록이 실행됩니다"하는 "" "ajax.responseText =!"signup_success의 논리 연산자를 변경, 그래서 다른 문제가 아니라면 조건부 로직에 앞서, 나는 그것을 테스트했고 PHP (아래)는 "signup_success"를 명확하게 리턴하고있다. 그 "if"진술에 문제가있을 것이라고 생각합니까?

여기 참조를 위해 PHP의 : 내가 말했듯이

<?php 
// Ajax calls this REGISTRATION code to execute 
if(isset($_POST["u"])){ 
    // CONNECT TO THE DATABASE 
    include_once("php_includes/db_conx.php"); 
    // GATHER THE POSTED DATA INTO LOCAL VARIABLES 
    $u = preg_replace('#[^a-z0-9]#i', '', $_POST['u']); 
    $e = mysqli_real_escape_string($db_conx, $_POST['e']); 
    $p = $_POST['p']; 
    $g = preg_replace('#[^a-z]#', '', $_POST['g']); 
    // GET USER IP ADDRESS 
    $ip = preg_replace('#[^0-9.]#', '', getenv('REMOTE_ADDR')); 
    // DUPLICATE DATA CHECKS FOR USERNAME AND EMAIL 
    $sql = "SELECT id FROM users WHERE username='$u' LIMIT 1"; 
    $query = mysqli_query($db_conx, $sql); 
    $u_check = mysqli_num_rows($query); 
    // ------------------------------------------- 
    $sql = "SELECT id FROM users WHERE email='$e' LIMIT 1"; 
    $query = mysqli_query($db_conx, $sql); 
    $e_check = mysqli_num_rows($query); 
    // FORM DATA ERROR HANDLING 
    if($u == "" || $e == "" || $p == "" || $g == ""){ 
     echo "The form submission is missing values."; 
     exit(); 
    } else if ($u_check > 0){ 
     echo "The username you entered is alreay taken"; 
     exit(); 
    } else if ($e_check > 0){ 
     echo "That email address is already in use in the system"; 
     exit(); 
    } else if (strlen($u) < 3 || strlen($u) > 16) { 
     echo "Username must be between 3 and 16 characters"; 
     exit(); 
    } else if (is_numeric($u[0])) { 
     echo 'Username cannot begin with a number'; 
     exit(); 
    } else { 
    // END FORM DATA ERROR HANDLING 
    // Begin Insertion of data into the database 
    // Hash the password and apply your own mysterious unique salt 
    $p_hash = md5($p); 
    // Add user info into the database table for the main site table 
    $sql = "INSERT INTO users (username, email, password, gender, ip, signup, lastlogin, notescheck) VALUES('$u','$e','$p_hash','$g','$ip',now(),now(),now())"; 
    $query = mysqli_query($db_conx, $sql); 
    $uid = mysqli_insert_id($db_conx); 
    // Establish their row in the useroptions table 
    $sql = "INSERT INTO useroptions (id, username, background) VALUES ('$uid','$u','original')"; 
    $query = mysqli_query($db_conx, $sql); 
    // Create directory(folder) to hold each user's files(pics, MP3s, etc.) 
    if (!file_exists("user/$u")) { 
     mkdir("user/$u", 0755); 
    } 
    //Email the user their activation link 
    //$to = "$e";  
// $from = "[email protected]"; 
// $subject = 'yoursitename Account Activation'; 
// $message = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Dilingle Message</title></head><body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;"><div style="padding:10px; background:#333; font-size:24px; color:#CCC;"><a href="http://www.dilingle.com"><img src="http://www.yoursitename.com/images/logo.png" width="36" height="30" alt="yoursitename" style="border:none; float:left;"></a>yoursitename Account Activation</div><div style="padding:24px; font-size:17px;">Hello '.$u.',<br /><br />Click the link below to activate your account when ready:<br /><br /><a href="http://www.yoursitename.com/activation.php?id='.$uid.'&u='.$u.'&e='.$e.'&p='.$p_hash.'">Click here to activate your account now</a><br /><br />Login after successful activation using your:<br />* E-mail Address: <b>'.$e.'</b></div></body></html>'; 
// $headers = "From: $from\n"; 
//  $headers .= "MIME-Version: 1.0\n"; 
//  $headers .= "Content-type: text/html; charset=iso-8859-1\n"; 
// mail($to, $subject, $message, $headers); 
    echo "signup_success"; 
    exit(); 
    } 
exit(); 
} 
?> 

은, PHP 스크립트의 끝에 "signup_success는"확실히 발사되지만, JS 위의 제대로 평가하지 않습니다.

미리 감사드립니다.

<?php 
^^^^ 

그리고 출력은 다음과 같습니다 :

signup_success 

이 스크립트에서 불필요한 공백을 제거하십시오 기준 PHP 코드, 당신이 당신의 스크립트에서 공백을 선도하고있다 한 제대로 게시된다고 가정

답변

2

또는 응답을 트림하십시오 :

if(ajax.responseText.replace(/^\s+|\s+$/g, "") == "signup_success") ... 
+0

당신은 그것을했습니다! 감사합니다 Salman A, 그리고 그와 같은 빠른 응답. 방금 두통 시간을 절약 해 주셨습니다. 다시 한 번 감사드립니다! – trevorj

관련 문제