我正在使用insert.php文件连接到数据库,插入用户的请求,发送成功确认消息,然后将用户重定向到同一页面。这是代码:
if (!mysqli_query ($db_conx, $sql)) {
die ('Error: ' . mysqli_error($db_conx));
}
else {
echo '<script type="text/javascript">';
echo 'alert("Thank you! Your request has been successfully sent.")';
echo '</script>';
}
header ('Location:http://www.mywebsite.com.au/page1.php');
mysqli_close ($db_conx);
问题是,在用户单击确认警报框上的“确定”后,页面从page1移至具有空白白屏的insert.php。我想刷新page1页面并保持原样。
if (!mysqli_query ($db_conx, $sql)) {
die ('Error: ' . mysqli_error($db_conx));
}
else {
echo '<script type="text/javascript">';
echo 'alert("Thank you! Your request has been successfully sent.")';
echo '</script>';
}
mysqli_close ($db_conx);
echo "<META http-equiv=\"refresh\" content=\"0;URL=page1.php\">";
我个人也永远无法header
正常工作,但meta refresh
始终按照我需要的方式工作。
在我的代码段中,我使用meta refresh
并告诉它等待0秒钟(content=\"0;
),然后重定向到page1.php页面(;URL=page1.php\"
),这样,在用户单击警报消息上的“确定”后,它将直接重定向到该页面。
另外,您可以在insert.php页面上输入不需要用户交互的确认消息,并且可以将重定向时间更改为2或3,以便用户有机会看到它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句