Kade Williams
Kade Williams

Reputation: 1181

How do I do a timed refresh/reload of a page without a POSTDATA warning in Javascript?

I am currently refreshing my page with

<script>function timedRefresh(timeoutPeriod){setTimeout('location.reload(true);',timeoutPeriod);}window.onload = timedRefresh(30000);</script>

But I am receiving a POSTDATA warning because it was wanting to resend a previous POST data form. I don't care of the post data is resent. It is not important for this site. I just want some way to refresh the page without the POSTDATA warning popping up.

Upvotes: 0

Views: 407

Answers (1)

Anadi Sharma
Anadi Sharma

Reputation: 295

The best way is to use PRG pattern, it prevents duplicate form submission. But if you still need a dirty way around (which is not recommended), you can use browser localStorage to maintain a flag.

timedRefresh(timeoutPeriod) { 
     localStorage.setItem('doResubmit', False);
     setTimeout(function () {window.location.reload(true);},timeoutPeriod);
}

Then, using localStorage.getItem('doResubmit'); just check whether or not you should send the request to server or not.

Let me know if it helps!

Upvotes: 1

Related Questions