简体   繁体   中英

How to show message or alert after page reload?

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 use localStorage.removeItem(key); or localStorage.clear();

On sessionStorage it remains till you close browser tab or sessionStorage.removeItem(key); or sessionStorage.clear(); .

Check Reference for localStorage and sessionStorage use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM