javascript - 警报消息框后面显示空白页

标签 javascript php

我正在客户端浏览器上显示一个消息框。它工作正常,但当弹出此警报消息框时,我在后面看到一个空白页。但我希望用户始终看到他的浏览页面并弹出此消息框。这是我的代码。` if($_POST['提交']=="保存") {

  $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");
  }

  }` 

最佳答案

当调用 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>';
}

关于javascript - 警报消息框后面显示空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32688900/

相关文章:

javascript - 将 Google Location LatLong 整数转换为 float

javascript - 如何将绝对定位的 div 水平居中于其相对定位的父级之上?

php - 在 JOIN MySQL 中选择除元素之外的所有元素

php - 提交按钮不响应操作

javascript - React Native - Firestore : Possible Unhandled Promise Rejection Can't find variable atob

javascript - 获取当前浏览器中的文本选择颜色和背景颜色

javascript - 如何更改此翻转卡以在单击时自行旋转?

php - 子类是否也可以继承父类的构造函数,或者每个类都必须有自己的构造函数?

php - 将数据从mysql插入到phpexcel的数组中

php - 将 PHP 部署到 Azure 网站