0

I would like to redirect the page if the condition inside the success will match the result of the test.php page that is "no_errors".

When the test.php page gives me an output of "no errors", the redirect function doesn't work. Thanks in advance.

$.ajax({
type: 'post',
url: 'test.php',
data: {user_name:tesseraval },
success: function (result) {       
    if(result === "no_errors") location.href = "ThankYou.html"
    else $( '#display_info' ).html(result);
}
});

test.php

<?php
try {
  if (isset($_POST['user_name'])) {
    $user = $_POST['user_name'];
    $z = sprintf('%08d', $user);
    include("conn/auth.php");
    include("conn/db.php");
    include("conn/restriction.php");
    $query_string = "SELECT * FROM data WHERE user LIKE  '%".$z."%' ;";
    if ($result = $con->query($query_string)) {
      if ($result->num_rows > 0) {
        if ($result->num_rows > 1) {
          echo " Attention! Duplicated ";
          while ($row = $result->fetch_object()) {
            echo '<table  id="table" class ="table"><thead> <th> ID </th><th>Name</th><th> fullname </th></thead><tbody>';
            echo '<tr><td id ="cod">'.$row->Code.'</td>';
            echo '<td>'.$row->name.'</td>';
            echo '<td>'.$row->fullname.'</td>';
            echo '</tr></tbody></table>';
          }
        } else {
          $query_string2 = " SELECT * FROM blacklist WHERE user = ".$z." ;";
          if ($result2 = $con->query($query_string2)) {
            if ($result2->num_rows < 1) {
              echo "no_errors";
            } else {
              echo " BLACKLISTED cannot be used";
            }
          }
        }
      } else {
        echo " NO RESULT  ";
      }
    }
  }
} catch (Exception $e) {
  header('HTTP/1.1 500 Internal Server Error');
}
?>      
Serge K.
  • 5,303
  • 1
  • 20
  • 27
OFBrc
  • 67
  • 1
  • 11

1 Answers1

0

First thing I would do is place the redirect outside of if, just to see if its the if that is not triggering for whatever reason. A good idea would also be to console.log(result) like CBroe said, both to see the result and also see if the success part of your ajax call even triggers.

sham
  • 1,214
  • 10
  • 16