Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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(){
    location.reload();
}

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

like image 447
deepak Avatar asked Nov 20 '12 15:11

deepak


2 Answers

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()

like image 107
Steven Moseley Avatar answered Sep 21 '22 14:09

Steven Moseley


I think you need to re-POST not re-load, as in HTTP POST rather than HTTP GET.

like image 27
John U Avatar answered Sep 21 '22 14:09

John U