简体   繁体   中英

How can I keep submitted form data after a page refresh?

Currently I have a page designed to automatically refresh after an interval of 10 seconds using the code:

<meta http-equiv="refresh" content="10" />

I also have a series of drop down menus so a user can select various elements, which will return a set of values I have stored in a database. The issue is after a form post, the data returned from the database is cleared from the browser after a refresh.

Is there a way to keep that data displayed even after an auto refresh?

This is my page: http://esp.southhills2013.info/php_test.php

使用ajax为用户保存选择的值,然后在用户访问此页面时使用此保存的值

Instead of auto-refreshing the entire page, try using AJAX to just reload the parts of the page that need updating.

You can probably even hack around this in jQuery by just sending an AJAX request for the current page, then getting the updated parts from the HTML and using .replaceWith() to update them on the page.

Depending the size and type of the data you could use a cookie or the session. If none of that is possible you can write the data to a file.

the best way to achieve this is by using SESSIONS

for example in php

<?php
session_start();
if(!empty($_POST['submit']))
{
  $_SESSION=$_POST;
}
?>

and in form

<select name="day">
<option value="1" selected="<?php $_SESSION['day']==1?"selected":''?>">1</option>
<option value="2" selected="<?php $_SESSION['day']==2?"selected":''?>">2</option>
.....
</select>
<!--or you can print in php using a loop-->

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM