JavaScript location.reload () loses messages

I try to reload the page using a java script, reload the page, but the mail data on the page does not load, after which the data is deleted, and reloading the page can help me with it.

function currencychange(xxx) { setTimeout('delay()', 2000); } function delay(){ location.reload(); } 

this is the javascript code i use to reload the onchange page

+4
source share
7 answers

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

The only ways to post are:

  • Use AJAX to send data back, get a new page and replace its body element or

  • Create a form element on the page with a valid window.location.href tag and place the data that you want to send back inside it as hidden inputs. Then, when calling the currency change form.submit()

+5
source

This is a known bug in Chrome. The problem is that Chrome does not perform POST when rebooting via JavaScript. If you did this using the reload button, it will behave correctly and ask the user if he wants to scan the data.

All the details are here: http://code.google.com/p/chromium/issues/detail?id=6429 [Edit: related error] https://bugs.webkit.org/show_bug.cgi?id=23735

PLEASE REGISTER THIS BECAUSE THIS GETS A FIXED FACTOR.

+1
source

It was a complete hack, but necessary and allowed him to work with Safari. So at the end of the page, I pushed all the message data into a session

 $_SESSION['post'] = $_POST 

Then I used jQuery to update session variables. Then use location.reload (); to reload the page as soon as I finished making the changes, and as soon as the page loaded, I simply moved all the session data to the message.

 $_POST = ยฃ_SESSION['post']; 

The result is the same as if the form was submitted.

+1
source

I think you need to reload POST without overloading, as in HTTP POST, not HTTP GET.

0
source

location.reload should not publish any data. If you need to send your data back to the server, consider submitting the form using method='post' (if you have one) or use AJAX (e.g. jQuery.post )

0
source

I solved the problem this way:

 // In the page called by POST, assuming coming from a search form // (ie searchResult.php) $working=array(); if ($_POST) { if(!isset($_POST["postArray"])) // Not set, first call $working = $_POST; else $working = unserialize($_POST["postArray"]); // recalled by someone else foreach ($working as $key => $value) { // Getting data $kv[] = "$key=$value"; // do something with input data.... } echo '<form action="newRequest.php" method="post">'; // Your data here ...... echo '<input type="hidden" name="currPost" value="' . htmlentities(serialize($working)) . '">'; echo '<input type="submit" value="Go!">'; echo '</form>'; } // end if($_POST) .... // This is the "newRequest.php" form $postDataReceiver=array(); foreach ($_POST as $key => $value) { // Getting data from searchResult.php $kv[] = "$key=$value"; switch($key) { // Your other stuff here ...... case "currPost": // Here we are! $postDataReceiver = unserialize($value); break; } // end switch } // end foreach echo '<form action="searchResult.php" method="post">'; // Your data here ...... echo '<input type="hidden" name="postArray" value="' . htmlentities(serialize($postDataReceiver)) . '">'; echo '<input type="submit" value="Go Back to search result!">'; echo '</form>'; 

Just a little tricky, but it works. Hope this helps! Better, Luke.

0
source

You can try the following:

 <form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="form" id="form"> </form> <script> // reload page every x miliseconds setInterval(function(){ // inser here the post variables. Examples: var input = document.createElement('input'); input.type = 'hidden'; input.name = 'id'; input.value = <?=$id?>; document.form.appendChild(input); var input2 = document.createElement('input'); input2.type = 'hidden'; input2.name = 'anotherid'; input2.value = <?=$anotherid?>; document.form.appendChild(input2); // send form document.form.submit(); }, 120000); </script> 
0
source

Source: https://habr.com/ru/post/1447252/


All Articles