Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload page with javascript without sending POST information again

I have a page, to which I POST information via form method="post". I would like to relaod it with JavaScript, but location.reload(true) and location.reload() makes browsers ask if I want to send the POST data again.

I would like to make JavaScript reload the page with GET instead of POST to skip the POST data.

How can I achieve that?

like image 393
Grzegorz Avatar asked Sep 01 '14 19:09

Grzegorz


2 Answers

window.location.href = window.location.href

try

like image 116
Vasiliy Vanchuk Avatar answered Nov 18 '22 13:11

Vasiliy Vanchuk


To reload a page without post data using javascript the easiest way I've found is to use an extra form to submit - this works regardless of whether the url is # or anything.

<form name="reloadForm">
    <button type="submit">
        Continue
    </button>
</form>
<script>
    document.reloadForm.submit() ;
</script>

That will show a button briefly on screen that the user can click continue on but the script will automatically submit it - this method sorts out a number of problems - the form is empty so it will not submit any post data (the button isn't named so even that won't submit a value). It works even if the url is set to #, and finally it gives a backup in case the user has disabled javascript (or the javascript doesn't work for some reason) they've still got a continue button available to click.

like image 36
TheKLF99 Avatar answered Nov 18 '22 14:11

TheKLF99