views:

218

answers:

3
+1  Q: 

javascript reload

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.

+1  A: 

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.

http://en.wikipedia.org/wiki/Post/Redirect/Get

Tim Snyder
basiclally trying to build a form, but when a user submits a form, I don't want to page to move anywhere, but I'd like for it to reload with the new information that was submitted.
Sakamoto Kazuma
It sounds like reading up on XMLHTTPRequest would be the best thing. What you are describing is what AJAX does.
Tim Snyder
+1 best to implement P/R/G first so it works nicely everywhere, then add ‘progressive enhancement’ XMLHttpRequest sauce on top if you really need it.
bobince
Any good reccomendations on reading material?
Sakamoto Kazuma
The mozilla dev area has a lot of useful information on AJAX nuts and bolts.https://developer.mozilla.org/En/AJAXJQuery and it's docs can provide you with a very simple way to do AJAX as well.
Tim Snyder
A: 

If you just want to reload the page without submitting the form try window.location=window.location;

Bob
A: 

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:

  1. Handle submit with AJAX
  2. When request completes, request only the changed portion of the page with AJAX
  3. Replace or Append the content on the page with the response to the second AJAX call
  4. Empty the form so it can be filled in again
Doug Neiner