3



I send a post request to the server, which inturn returns a JSP. Now if i use the refresh button of the browser, i get a confirmation to resubmit the data, and then the page reloads successfully.

However, when i try to refresh the page using javascript, i dont get any confirmation box, and the reload also doesnt work. Ive tried all methods of reload like :

  • location.reload()
  • window.location.reload()
  • window.location.href = window.location.href
  • history.go(0);

I think the problem is that its sending a get request when i try to refresh using javascript, and it is not able to find the necessary paramaters.

This problems occurs only in chrome... it works in Firefox and IE!!

Purav Shah
  • 523
  • 1
  • 4
  • 13
  • http://stackoverflow.com/questions/570015/how-do-i-reload-a-page-without-a-postdata-warning-in-javascript – c69 Oct 04 '11 at 07:52

5 Answers5

1
parent.window.location.reload(true);

worked on chrome for me ... finally

explanation: of parent.window

A reference to the parent of the current window or subframe.

If a window does not have a parent, its parent property is a reference to itself.

When a window is loaded in an , , or , its parent is the window with the element embedding the window.

Mustkeem K
  • 8,158
  • 2
  • 32
  • 43
Steve
  • 11
  • 1
1

The reload method may use the cache to reload the page. Specify the force parameter to make it get the page from the server:

window.location.reload(true);
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

The only solution is to call the same URL with some additional value.

This is regular reloading script, this works fine on IE & FF but not on Chrome & Safari.

window.location = location.href; 

To make reload work on all browser types use:

window.location = location.href + '?session=' + sMath.floor((Math.random() * 1000000) + 1);

Tested on IE, FF, Chrome and Safari.

ikos23
  • 4,879
  • 10
  • 41
  • 60
  • Adding a random key to the page link should do the trick. The point is that browser will not reload until page link is changed. – Rehmat Mar 26 '21 at 12:49
0

I tried all the possible solutions found (ajax calls, various snippets) but the only thing worked for me was disabling the network cache from chrome see here Why isn't Google Chrome reloading my scripts? I don't think it is a solution for production but while developing can spare you some time from searching. The problem seems to be with chrome's cache and even setting

window.location.reload(true);

does not clear the cache while reloading. On FF works fine.

Cheetara
  • 165
  • 1
  • 5
  • 14
-1

In order to "refresh" the page via a post request, you need to submit a form. You can use any form already on the page, or create one programmatically.

var myForm = document.createElement("form");
myForm.action = "/my/url.jsp"; // Or use window.location, or something else.
myForm.method = "POST";
document.body.appendChild(myForm); // Needs to be in the DOM. Is not visible.
myForm.submit();
August Lilleaas
  • 54,010
  • 13
  • 102
  • 111
  • The problem is this: i submit a form on page 1. It takes me to page 2. now when im on page 2, if i click on browser's reload, then page 2 refreshes successfully (after getting a confirmation). However, if i put a this: `Reload` on page 2, and if i click on it, then i cant reload the page, since it doesnt send the necessary params of page1 form. My question is that is it possible to implement the same functionality of browser's reload button? – Purav Shah Oct 04 '11 at 08:02