gpt4 book ai didi

javascript - 如何在客户端调用flash?

转载 作者:行者123 更新时间:2023-11-29 21:11:26 26 4
gpt4 key购买 nike

代码:

登录.ejs

<script>
req.flash('success_msg', 'You have logged in');
</script>

header.ejs

<div class = "alertMessage">

<% if (success_msg != false){ %>
<span class="alert alert-success containerMargins">
<%= success_msg %>
</span>
<% } %>
<% if (error_msg != false){ %>
<span class="alert alert-danger containerMargins">
<%= error_msg %>
</span>
<% } %>

</div>

情况:

这与在服务器端使用 flash 并在客户端显示消息无关:它已经非常适合我。

这与从客户端调用 flash 或使用其他库从客户端复制相同的行为有关。


问题:

我展示的代码当然不能在客户端运行,我可以做些什么来在客户端复制该行为?

最佳答案

The flash is a special area of the session used for storing messages. Messages are written to the flash and cleared after being displayed to the user. The flash is typically used in combination with redirects, ensuring that the message is available to the next page that is to be rendered.

所以你需要的代码:

  1. 将一些数据存储在客户端可以在页面之间访问的地方
  2. 读取该数据
  3. 阅读后删除

从选择 somewhere 开始对于选项 1(例如 localStorage 或 cookie)。其余的应该是微不足道的 - 原始模块大约是 80 lines of code, including about 50% comments — 实现(但具体到您做出的选择)。

关于javascript - 如何在客户端调用flash?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41696629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com