user186826
user186826

Reputation:

Reload and display message

I want to reload page after deleting a row from table, and then display 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 messageSpan content has been changed, so the reload function wipes out the messageSpan content.

Upvotes: 3

Views: 11089

Answers (4)

Si8
Si8

Reputation: 9225

Displaying a message after a page has been refreshed can be accomplished with the following:

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);
});

Loader image:

Loadere

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

Upvotes: 1

Daniel Brink
Daniel Brink

Reputation: 2504

don't use reload. use the query string to pass a value back to your page to tell it whether the delete operation was successful or not

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

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

but have a look at jquery and ajax, you might not have to do the postback at all to refresh your grid

Upvotes: 1

Nick Bedford
Nick Bedford

Reputation: 4435

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

Upvotes: 0

Christian C. Salvad&#243;
Christian C. Salvad&#243;

Reputation: 827366

If you are trying to show the message for a defined 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);
}

Note that your message will be visible only for those three seconds, it will disappear when the page reloads.

Upvotes: 1

Related Questions