2017-09-05 3 views
0

Ich möchte die Seite umleiten, wenn die Bedingung innerhalb der Erfolg wird das Ergebnis der test.php Seite, die "no_errors" ist.Umleitung Seite nach Abfrage Ergebnis mit Ajax

Wenn die Seite test.php gibt mir eine Ausgabe von "keine Fehler", funktioniert die Umleitung Funktion nicht. Danke im Voraus.

$.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'); 
} 
?>  
+4

'console.log (Ergebnis)' zeigt was genau? – CBroe

+1

versuchen Sie es als 'window.location.href' –

+0

Mögliches Duplikat von [Wie zu einer anderen Webseite umleiten?] (Https://stackoverflow.com/questions/503093/how-to-redirect-to-another-webpage) – Alexander

Antwort

0

Das erste, was ich tun würde, ist die Umleitung außerhalb von if zu platzieren, nur wenn ihr die if zu sehen, die aus irgendeinem Grund nicht auslöst. Eine gute Idee wäre auch zu console.log(result) wie CBroe sagte, sowohl um das Ergebnis zu sehen als auch um zu sehen, ob der success Teil deines Ajax Anrufs überhaupt ausgelöst wird.