【问题标题】:how to show alert in the redirected page?如何在重定向页面中显示警报?
【发布时间】:2021-11-29 18:28:28
【问题描述】:

在 index.php 中我有 3 个按钮(添加、删除、编辑)

如果我点击删除它将重定向到删除页面查询(delete.php)

删除成功后,页面跳转到index.php,并且会弹出sweet alert2提示成功(删除成功)

如果我添加一个用户,msg 将变为添加成功

这取决于我重定向到 index.php 的位置

那我能做什么?

【问题讨论】:

标签: javascript php


【解决方案1】:

解决方案1

在重定向之前,您应该创建一个会话对象并将警报消息保存在会话中。

start_session()

$_SESSION["alert"] = ["type" => "success", "message" => "User deleted successfully"];

在 index.php 页面上

在 index.php 页面上,检查是否有 flash/alert 消息。如果有,输出并删除。

if (isset($_SESSION["alert"]))
{

echo 

"<div class='alert alert-success alert-dismissible'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <h4><i class='icon fa fa-check'></i> Alert!</h4>
                 $_SESSION["alert"]
              </div>";
  
unset($_SESSION["flash"]);
}

就是这样。

【讨论】:

    【解决方案2】:

    在从 delete.php/edit.php 重定向到 index.php 时,您可以传递一些查询参数。

    从 delete.php 重定向看起来像 index.php?msg="deleted succeeded";

    从 edit.php 重定向看起来像 index.php?msg="add successfully"

    在 index.php 中你可以读取查询字符串 msg 并显示警告框

    这里是获取查询字符串参数的参考。

    How can I get query string values in JavaScript?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-20
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 2018-07-29
      • 2016-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多