Is it possible to use javascript:location.reload(true) as a action= for a form without having the browser say "In order to reload this page, information must be resent" or something similar to that? Form action is currently being handled by onsubmit= instead.
Reload will always ask the question about information being resent if the user came from POSTing data. It's hard to answer anything specific as I don't know what you are trying to do. This is something that is in the browser's history and can't be prevented.
A better solution is to use the PRG pattern.
If you just want to reload the page without submitting the form try window.location=window.location;
It seems you are handling your form with an AJAX request in the onsubmit
event, which begs the question why since nothing is gained if you have to refresh the page anyway. I would suggest either using a normal post from the form, or use @Bob 's solution (which he saved me from typing by posting first). If you use window.location=window.location
be sure to call it after whatever happens in your onsubmit
method has completed or you may introduce a race condition where it redirects before your onsubmit method has finished sending the data.
Edit:
Just read your comment that provided more information. Again, reloading the whole page in response to an AJAX submit completely defeats the purpose of using AJAX. You really should consider using a Javascript Library like jQuery to help you with this. Basically the pattern would be as follows:
- Handle submit with AJAX
- When request completes, request only the changed portion of the page with AJAX
- Replace or Append the content on the page with the response to the second AJAX call
- Empty the form so it can be filled in again