[英]Alert box stuck in endless loop
I have an alert
box which is supposed to refresh the page when the user clicks OK. 我有一个
alert
框,当用户单击“确定”时,该框应刷新页面。 Instead of this happening, the alert box disappears and then reappears when the user clicks OK. 代替这种情况,警报框消失,然后在用户单击“确定”时重新出现。
It's stuck in an endless loop of re-appearing! 它陷入了无休止的重新出现!
<?php
if(isset($_POST['submit'])) {
echo'
<script>
alert(\'Reply successfully flagged!\');
window.location.reload();
</script>
';
}
?>
<form method="post">
<input type="submit" name="submit">
</form>
Note: I need the alert
to be in the if
statement - I can't just use pure Javascript (such as onclick
)! 注意:我需要在
if
语句中发出alert
-我不能只使用纯Javascript(例如onclick
)!
The problem here is, when you make a reload, it will trigger the POST
parameters to be sent, ie, the $_POST['submit']
will be set . 这里的问题是,当您进行重新加载时,它将触发
POST
参数的发送,即$_POST['submit']
将被设置 。 It is better to set a SESSION
flag instead. 最好设置一个
SESSION
标志。
<?php
if(isset($_POST['submit'])) {
echo'
<script>
alert(\'Reply successfully flagged!\');
location.href = location.href;
</script>
';
}
?>
change 更改
window.location.reload();
with 与
location.href = window.location.href;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.