Himan Himan - 3 years ago 110
Javascript Question

using jquery localstorage to reload page and display a message

Working on the section, i had used localstorage to load the page, but i am bit confused as i want to pass a custom message to display

My usage till now:

success: function(data) {
if ($.trim(data) == 'Complete') {
localStorage.setItem("Success","Thanks this is complete")
location.href = 'index';
}


and at the top i have this: after document ready

if(localStorage.getItem("Success"))
{
$(".msg").html(data); - data i want the message to be appearing which i defined in the localStorage.setItem("Success","Thanks this is complete")
localStorage.clear();
}

Answer Source

using the get method from local storage should do the trick localStorage.getItem("Success")

if(localStorage.getItem("Success"))
{
    $(".msg").html(localStorage.getItem("Success") ); 
    localStorage.clear();
}

LocalStorage is window property and not jquery function....

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download