简体   繁体   中英

how to make the data in the page not disappear when the page is refreshed

Is it possible for data in the table not disappear when u press f5? here is my code:

function Display_Start_Data(down_Time_Start) {
     console.log(downTimeStart);
     var newContent = '';

        $.each(downTimeStart.data, function (i, item) {
            newContent += Hesto.Html.StartTR(item.downTimeStart);
            newContent += Hesto.Html.CreateTD('<input type="button" value="Stop" id="btnStopEvent">');      
            newContent += Hesto.Html.CreateTD(item.CategoryName);
            newContent += Hesto.Html.CreateTD(item.StartTime);
            newContent += Hesto.Html.CreateTD(item.EndTime);
            newContent += Hesto.Html.CreateTD(item.Comments);
            newContent  = Hesto.Html.EndTR(newContent);
        });
        $('#DowntimeList').append(newContent);     
 }

您可以将数据保存在浏览器的本地存储中,但并非所有浏览器都支持。

You can do it either by using server side sessions or client side cookies. You can use Html5 local storage but it may only work on latest browsers.

Possible via:

  1. custom procedure to save/recall from cookies.
  2. custom procedure to save/recall from local storage.
  3. custom procedure to save/recall from server side.

Simple and one line answer would be No .

You cannot save the data using jQuery. It is a job of Cache (Serverside or client side) or localStorage (HTML5; in browser). Otherwise, you'll get a new page each time the page is loaded pressing F5 .

When the user presses F5 button. The browser sends a request to the server to load the page, the page is loaded with the content that is sent by the server. No extra data is appened to the page by the browser. That is why, no data is saved once the user presses F5.

For this purpose, developers use some other technologies in saving the user's sessions. Some of the example of what are

Cache

Cache is of two types, one is saved by the server. Other is saved by the client itself (client-side agent; aka Browser).

You can learn this from other companies and their developer helping guides.

https://developers.google.com/speed/docs/best-practices/caching

localStorage

HTML5'a API introduced a new element known as localStorage; not an element, its a plugin or what you can call a new technology. In it, you can store the data in the client-machine; computer. Which can be used once again.

Using this you can store the data; form data, in the computer and then get it back once the user presses F5.

You can learn about its API on Mozilla Developer Guide

https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage

Good luck!

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