开发者

javascript reload

Is it possible to use javascript:location.reload(true) as a action= for a form witho开发者_StackOverflow中文版ut 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.

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


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:

  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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜