如果成功中的条件与test.php页面的结果“no_errors”匹配,我想重定向页面。
当test.php页面给出输出“无错误”时,重定向功能不起作用。提前谢谢。
$.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');
}
?>
答案 0 :(得分:0)
我要做的第一件事就是将重定向放在if
之外,只是为了看看if
是否由于某种原因没有触发。像CBroe所说的那样console.log(result)
也是一个好主意,既可以查看结果,也可以查看ajax调用的success
部分是否触发。