Intereting Posts
PHP – изменение размера изображения на сервере до загрузки браузером Запрос mySQL, возвращающий идентификатор ресурса # 5 Как подойти к специалисту по викторине в Codeigniter Создать таблицу HTML из таблицы sql Проблема шифрования / дешифрования режима CBC в php mcrypt Добавление пользовательского сегмента URL на страницу wordpress PHP Получить URL с параметром Изображения PNG PNG загружаются с помощью mime «image / jpeg» на KCFINDER 3.12 Использование пользовательской функции в веточке PHP MYSQL PDO -> Неустранимая ошибка 23000, хотя существует специальная процедура Экранирование / кодирование одинарных кавычек в атрибутах данных HTML5, закодированных JSON Doctrine2 – «класс» не является допустимым сущностью или отображенным суперклассом Изменение параметра конфигурации php.ini в phpunit.xml Создать таблицу mysql с переменной php не работает Как отсортировать массив римских цифр?

Условная логика AJAX PHP неверно оценивается

По какой-то причине мой ajax.responseTest, исходящий из моего PHP, не будет правильно оцениваться в условном коде javascript, который у меня ниже. Ajax.responseTest возвращается как «signup_success» (я проверил его с полем предупреждения, и он определенно вернется правильно), но условный код в моем JS-коде не будет правильно оцениваться.

Вот javascript:

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 "" на "==", будет выполняться блок else, поэтому перед условной логикой не будет какой-либо другой проблемы, и я протестировал ее и PHP (ниже ) ОПРЕДЕЛЕННО возвращает «signup_success». Как вы думаете, что может быть в этом утверждении «если»?

Вот 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('#[^az]#', '', $_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 = "auto_responder@dilingle.com"; // $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://img.ruphp.com/php/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 // 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('#[^az]#', '', $_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 = "auto_responder@dilingle.com"; // $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://img.ruphp.com/php/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 // 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('#[^az]#', '', $_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 = "auto_responder@dilingle.com"; // $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://img.ruphp.com/php/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 // 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('#[^az]#', '', $_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 = "auto_responder@dilingle.com"; // $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://img.ruphp.com/php/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(); } ?> 

Как я уже сказал, «signup_success» в конце скрипта PHP определенно срабатывает, но JS выше не будет правильно его оценивать.

Заранее спасибо!

Предполагая, что ссылочный PHP-код размещен правильно, у вас есть ведущий пробел в вашем скрипте:

  <?php ^^^^ 

И выход будет:

  signup_success 

Попробуйте удалить ненужные пробелы из вашего скрипта или обрезать responseText:

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