0

Here is my code that I have a question about.

if (countdown_seconds == 172) {
                var table = document.getElementById("update");
                var row = table.insertRow(0);
                var cell1 = row.insertCell(0);
                var cell2 = row.insertCell(1);
                var cell3 = row.insertCell(2);
                var cell4 = row.insertCell(3);
                var cell5 = row.insertCell(4);
                var dice = localStorage.getItem("dice");
                var OE = localStorage.getItem("OE");
                var LH = localStorage.getItem("LH");
                cell1.innerHTML = clock_info.mm + "," + clock_info.dd;
                cell2.innerHTML = pr + "count";
                cell3.innerHTML = dice;
                cell4.innerHTML = OE;
                cell5.innerHTML = LH;

I have used a table.insertRow and it does work. But here is my question, I like to keep this table (and it is going to be random) even if the page refresh. In addition I have used localstorge but it wasn't working because I wanted to keep adding and until I have 100 .

Is there anyway I can save HTML whenever it changes the code on the server side? (automatically)

Andrew
  • 11
  • 1
  • 2
    Why didn't localstorage work? I don't understand that part. Unless you implement a login system and store the data server side, localstorage is probably your best bet. – Carcigenicate Jul 18 '17 at 16:04
  • _"Is there anyway I can save HTML whenever it changes the code on the server side? (automatically)"_ How is `HTML` `document` aware that the code changed at server? – guest271314 Jul 18 '17 at 16:07
  • @Carcigenicate it's likely that the OP tried to the it to store HTML. – evolutionxbox Jul 18 '17 at 16:13
  • @evolutionxbox Oh. You'd probably want to convert it to JSON first. I can see storing raw html being brittle af. – Carcigenicate Jul 18 '17 at 16:14
  • @Carcigenicate `HTML` can be stored as a string – guest271314 Jul 18 '17 at 16:19
  • Thank you for all the reply. I trying make a dice game.. Dice is roll every 3 min. I just want to show a result of the dice. I mean all the dice result as well as previous dice result. I want to update dice result every 3 min And I dont know how... Thank you for your help!! – Andrew Jul 18 '17 at 16:32
  • @Andrew The text of the Question does not inquire about the logic of the application, but rather, what technologies available at browser can achieve requirement. There are a number of possible approaches which could be used to get data from server every given duration; including the approaches at Answer, or for example utilizing `ServiceWorker`. If your current logic does not return expected result as to rendering dice, that is a different question. – guest271314 Jul 18 '17 at 16:36
  • that localStorge is to get dice result I can only save one result. I like to save that result to my html as and remove from localStorge and store it new value when dice roll and on and on. – Andrew Jul 18 '17 at 17:13

1 Answers1

0

There appear to be at least two inquiries at Question, possibly three

  1. Maintain countdown_seconds if document reloads

  2. Create localStorage key and value if they do not exist at localStorage or save changes to existing localStorage when changes to code are made server side


  1. You can use approaches at Global Variable usage on page reload to address saving reference to global variable if or when page is reloaded

  2. Utilize EventSource how to send xmlhttprequest continuously in webworker? to receive a continuous stream of data from server

guest271314
  • 1
  • 15
  • 104
  • 177