我正在客户端浏览器中显示一个消息框。它工作正常,但当弹出此警告消息框时,我看到后面有一个空白页面。但我希望用户始终看到他的浏览页面,然后弹出此消息框。这是我的代码 如果($ _ POST ['提交'] =="保存&#34) {
$language=$_POST['pbx_lan'];
if($language!="")
{
$query="update `account_detail` set `prompt_language`= '$language' WHERE `org_id`='".$_SESSION['account_id']."'";
$result = $mysqli->query($query) or die($mysqli->error);
$_SESSION['check_update'] = "1";
// setcookie("msg","Language Successfully Updated",time()+5,"/");
echo '<script>
confirm("You have selected '.$language.'");
window.location = "'.SITE_URL.'index.php?view=pbx_prompts."
</script>';
// header("location:".SITE_URL."index.php?view=view_service");
}
else
{
setcookie("err","No Language Selected.Please Select Language",time()+5,"/");
header("location:".SITE_URL."index.php?view=view_service");
}
}`
答案 0 :(得分:1)
当调用confirm()
时,页面停止加载。当您在页面末尾添加confirm()
时,页面会在confirm()
显示之前加载
<body>
TEST123
<script>
confirm('test');
</script>
</body>
而不是
<body>
<script>
confirm('test');
</script>
TEST123
</body>
对于您的代码,这意味着
echo '<script>
confirm("You have selected '.$language.'");
window.location = "'.SITE_URL.'index.php?view=pbx_prompts."
</script>';
必须移到body
标记的底部
同时复制所需的if
语句,以便仅在需要时执行代码。
body
标记底部的完整代码应该是这样的:
if (!empty($language) && $_POST['submit'] == "Save") {
echo '<script>
confirm("You have selected '.$language.'");
window.location = "'.SITE_URL.'index.php?view=pbx_prompts."
</script>';
}