I am using Jquery Toastr to show some success message. 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.
Is there any way to do this? I want to do this after ajax success.
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
success: function(data) {
if (data.OperationStatus) {
localStorage.setItem("Status",data.OperationStatus)
window.location.reload();
}
You can also do it with sessionStorage
. Replace localStorage
with sessionStorage
in current code and whole code works with sessionStorage
.
On
localStorage
works like cookies get data until you uselocalStorage.removeItem(key);
orlocalStorage.clear();
On
sessionStorage
it remains till you close browser tab orsessionStorage.removeItem(key);
orsessionStorage.clear();
.
Check Reference for localStorage and sessionStorage use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With