如何在使用php和jscript重定向到其他页面后显示警报消息?
问题很简单 我有一个表单提交成功提交表单后,我想在下一页打印“表单成功提交!”如何在使用php和jscript重定向到其他页面后显示警报消息?,php,Php,问题很简单 我有一个表单提交成功提交表单后,我想在下一页打印“表单成功提交!” 使用php和jscript保存表单后,您可以使用以下命令在带有警报脚本的页面上重定向用户: // PHP header('Location: http://www.example.com/path_to_page'); 然后在该页面上可以添加js // Js (include jquery before it) <script> $(document).ready(function(){
使用php和jscript保存表单后,您可以使用以下命令在带有警报脚本的页面上重定向用户:
// PHP
header('Location: http://www.example.com/path_to_page');
然后在该页面上可以添加js
// Js (include jquery before it)
<script>
$(document).ready(function(){
alert('Form successfully submitted!');
});
</script>
//Js(前面包括jquery)
$(文档).ready(函数(){
警报(“表单已成功提交!”);
});
如果不使用jquery,请使用:
<body onload="alert_call()">
<!-- your page content -->
<script>
function alert_call(){
alert('Form successfully submitted!');
}
</script>
</body>
函数警报_调用(){
警报(“表单已成功提交!”);
}
我从Laravel那里学到了这种方法,它叫flash message。
基本上,您在会话中设置了一些变量(您在命名中的选择)
//从您的原始页面
+1我们的一位客户确实要求实施“询问按摩”,因此这似乎是一个相关的问题:我很高兴我的问题有帮助
//from your originating page
<?php
$_SESSION["flash"] = array();
$_SESSION["flash"]["message"] = "Your message";
$_SESSION["flash"]["status"] = "error";
?>
<?php
//to your destination page
if(isset($_SESSION["flash"])){
echo $_SESSION["flash"]["message"];
//or
echo "<script>alert('{$_SESSION["flash"]["message"]}');</script>";
unset($_SESSION["flash"]);
}
?>