deepak deepak - 1 year ago 134
Javascript Question

JavaScript location.reload() is losing post data

I am trying to reload the page using java script the page reloads but the post data in the page is not loading the post data are deleted while the page reloads can any one help me with it

function currencychange(xxx) {
setTimeout('delay()', 2000);
function delay(){

this is the javascript code which I am using to reload the page onchange

Answer Source

window.location.reload() issues a GET, so yes, the POST data will be lost.

The only ways you can issue a post are either:

  1. Use AJAX to post the data back, get the new page, and replace your body element with it, or

  2. Create a form element on the page with the action being the current window.location.href, and place the data you want to post back inside it as hidden inputs. Then, on currency change call form.submit()