[英]redirect to another html file using php
I currently want to redirect to another HTML file (ie dashboard.html) after the user has successfully. 我当前要在用户成功后重定向到另一个HTML文件(即dashboard.html)。 I know I can use header to solve this, but I am not sure where should I add it into my code.
我知道我可以使用标头来解决此问题,但是我不确定应将其添加到代码中的哪个位置。
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));
}
Cheers for your kindly help. 为您的帮助加油。
You can either add an <a>
tag into the code built by PHP: 您可以在PHP构建的代码中添加
<a>
标记:
<a href="new_page.php">Click this link for new page</a>
Or, you can use javascript/jQuery to trap a user click and redirect them to a new page: 或者,您可以使用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>
Or, if headers have already been sent and the PHP header()
method specified in joakkinen's answer won't work, you can echo this HTML: 或者,如果已经发送了
header()
在joakkinen的答案中指定的PHP header()
方法不起作用,则可以回显此HTML:
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=new_page.php">';
(the content=0 represent number of seconds delay before redirect) (content = 0表示重定向之前的延迟秒数)
I can add ... 我可以添加...
header('Location: dashboard.html');
exit;
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 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!');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.