Refresh and display message

I want to reload the page after deleting a row from the table and then display a message. Below is the JavaScript code:

if(action == 'delete'){
  window.location.reload(true);
  //tried to set timeout here, no luck :(
  document.getElementById('messageSpan').innerHTML = "The value has been deleted."; 
}

      

It seems that the reload function is executed after the content has messageSpan

been changed, so the reload function erases the content messageSpan

.

+2


source to share


4 answers


If you are trying to show a message for a specific period of time and then reload the page, you can use the setTimeout function:

if(action == 'delete'){
  document.getElementById('messageSpan').innerHTML = "The value has been deleted."; 

  setTimeout(function () { // wait 3 seconds and reload
    window.location.reload(true);
  }, 3000);
}

      



Please note that your message will only show for those three seconds, it will disappear on page reload.

+1


source


do not use reboot. use a query string to pass a value to the page to tell if the delete operation was successful or not.

i.e. self.location.href = "yourPage.html? result = success"



your page should then check the query result string string and display the appropriate message.

but look at jquery and ajax, you may not need to do postbacks to update your grid.

+1


source


Displaying the message after refreshing the page can be done like this:

HTML (insert anywhere in the BODY tag):

<div id="dvLoading"></div>

      

CSS

#dvLoading {
    background:url(../theImages/loader.gif) no-repeat center center;
    height: 100px;
    width: 100px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin: -25px 0 0 -25px;
    z-index: 9999999999999999;
}

      

JQuery

$(window).load(function() {
    $('#dvLoading').fadeOut(2000);
});

      

Bootloader image:

Loadere

Worked like a charm for me. Hope this helps with your question.

+1


source


Reloading the page will destroy the page state and thus the user will never see the HTML message because it gets reset on page reload.

0


source







All Articles