我目前想要在用户成功后重定向到另一个HTML文件(即dashboard.html)。我知道我可以使用标头来解决这个问题,但我不确定我应该在哪里将它添加到我的代码中。
column = (column + 1) % numberOfColumns
为你的帮助干杯。
答案 0 :(得分:0)
您可以在PHP构建的代码中添加<a>
标记:
<a href="new_page.php">Click this link for new page</a>
或者,您可以使用javascript / jQuery来捕获用户点击并将其重定向到新页面:
<div id="redir">Click this link</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function(){
$('#redir').click(function(){
window.location.href = 'new_page.php'
});
});
</script>
或者,如果标题已经发送并且joakkinen的答案中指定的PHP header()
方法无效,您可以回复此HTML:
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=new_page.php">';
(content = 0表示重定向前延迟的秒数)
答案 1 :(得分:0)
我可以添加......
header('Location: dashboard.html');
exit;
答案 2 :(得分:0)
if (mysqli_query($Link, $Query)) {
$lastID = mysqli_insert_id($Link);
$Query2 = "INSERT INTO $table_2 VALUES (NULL,
'".$lastID."')";
if (mysqli_query($Link, $Query2)) {
$message = "You've sucessfully created the account!";
echo json_encode(array('success'=>'true', 'action'=>'login','html'=>$message, 'console.log'=>$Query));
}
else {
$message = "Error occur in query2";
echo json_encode(array('action'=>'error','html'=>$message, 'console.log'=>$Query));
}
}
else {
$message = "Error in query1";
echo json_encode(array('action'=>'error','html'=>$message, 'console.log'=>$Query));
}
<强>的jQuery 强>
$.ajax( {
type: 'POST',
dataType: 'json',
data: postData,
url: 'n3228691.scm.tees.ac.uk/Yii/MACC/models/…';,
success: function(data) {
console.log(data);
if(data.action === "login"){
window.location="dashboard.html"; //succeed insert
}else{
alert('There was an error handling your registration!');
}
},
error: function(data) {
alert('There was an error handling your registration!');
}
});