开发者

Reload and display message

I want to reload page after deleting a row from table, and then d开发者_如何学Cisplay 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.


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.


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


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:

Reload and display message

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜