Reputation: 111
How to refresh and reload the page without resending the POST data?
I have tried location.reload()
which works absolutely fine on Chrome(which was the testing environment while development). But IE and Firefox went into an Infinite Loop in JS - reposting a lot of junk/duplicate data.
Note: However, I just want to refresh the page to clear all the form contents. I am also registering a start up script after Submit, that will show the alert message that data was added successfully.
HELP!
Upvotes: 8
Views: 25970
Reputation: 1464
Simple way:
history.replaceState(null, document.title, location.href)
Upvotes: 0
Reputation: 292
I've try reload too, and reload(true) both not exactly doing what I wanted.
I've seen that Location Object have other method (than reload) since I wanted to request the page in "get" I just did:
location.assign(window.location);
So far seem to be doing what I want, reload the same page without submitting again values. My use case is an ajax call to the server when session has expired. I display an error message saying that the session is lost, then I want the page to reload.
Upvotes: 0
Reputation: 657
location.href = location.href + '?' + Math.random();
This should work.
Upvotes: 6
Reputation: 21
The following will solve your problem:
Server.Transfer(Request.RawUrl);
Upvotes: 2
Reputation: 15934
If you just want to clear the form, why not:
<input type="reset" value="Clear Fields">
You could also do it using:
document.getElementById('<%=form1.ClientID%>').reset();
Seems a waste to reload the page unless you need to do something else as well.
Upvotes: 2