Reputation: 361
I'm programming a web-app which uses text-boxes for the following purposes: Insert data (by the user), display the results.
The app is used this way:
The user inserts data, an exec button is clicked. The result is calculated and presented to the user in text-boxes.
Now the user can click a reset-button for to move the app to it's initial state. So that a new usage becomes possible.
The JavaScript which is triggered by the reset-button:
wr.reset.addEventListener('click', function() {
location.reload();
})
I used these code with the local Apache-installation which I use for developing. Everything was fine. The page was reloaded. The textboxes where all set to their initial state => the hyphen which I define as "value".
<div class="vertical-pair col-xs-4">
<label for="word-count">Complete word-count:</label>
<input type="text" id="word-count" value=" - " />
</div>
Now I've tried out the app on a real server (runned by a webhoster) and had the following result:
The page was reloaded but the content of the input-boxes persisted.
Means: The data which the user has entered are still in the boxes after executing the reset-button.
What causes these different behaviours (on the local Apache-installation and on the live-server)?
Currently I have replaced 'location.reload()' to 'location.href = "URL of the page itself"'.
Is this aproach a valid alternative or does it have flaws?
Upvotes: 1
Views: 53
Reputation: 14982
Just use true
first argument to disable browser cache on reload.
Syntax:
location.reload(forcedReload);
Parameters
forcedReload Optional
Is a Boolean flag, which, when it is true, causes the page to always be reloaded from the server. If it is false or not specified, the browser may reload the page from its cache.
Upvotes: 1