[英]How to show message or alert after page reload?
I am using Jquery Toastr to show some success message. 我正在使用Jquery Toastr来显示一些成功消息。 It is just like alert for some time. 它就像警报一段时间。
I want to show some message after page reload. 我想在页面重新加载后显示一些消息。 The problem is when page is reloaded all javascript is reload. 问题是当页面重新加载时所有的javascript都重新加载。
Is there any way to do this? 有没有办法做到这一点? I want to do this after ajax success. 我想在ajax成功之后做到这一点。
success: function(data) {
if (data.OperationStatus) {
window.location.reload(); //Reload the page
Toaster.show("The record is added"); //I want to show here.But it will never show because when page is loaded javascript is also loaded.
}
}
Is there any efficient way to do this? 有没有有效的方法来做到这一点?
You have to do like this 你必须这样做
$(document).ready(function(){
//get it if Status key found
if(localStorage.getItem("Status"))
{
Toaster.show("The record is added");
localStorage.clear();
}
});
on ajax call set local storage 在ajax调用设置本地存储
success: function(data) {
if (data.OperationStatus) {
localStorage.setItem("Status",data.OperationStatus)
window.location.reload();
}
You can also do it with sessionStorage
. 您也可以使用sessionStorage
。 Replace localStorage
with sessionStorage
in current code and whole code works with sessionStorage
. 在当前代码中将localStorage
替换为sessionStorage
,整个代码与sessionStorage
。
On
localStorage
works like cookies get data until you uselocalStorage.removeItem(key);
在localStorage
工作就像cookie一样获取数据,直到你使用localStorage.removeItem(key);
orlocalStorage.clear();
或localStorage.clear();
On
sessionStorage
it remains till you close browser tab orsessionStorage.removeItem(key);
在sessionStorage
它一直保持到关闭浏览器选项卡或sessionStorage.removeItem(key);
orsessionStorage.clear();
或sessionStorage.clear();
. 。
Check Reference for localStorage and sessionStorage use. 检查参考是否存在localStorage和sessionStorage 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.