0

The table is on a repo. The table is blank, but users can upload info into the <td> cells by a text space and button function.

<input type=“text” id=“one”>
<button onclick=“upload()”>

JavaScript

function upload(){
  this.disabled = true
  document.getElementById(“targetTDElement”).innerText = document.getElementById(“one”).value
}

By synchronizing, I mean by when user A uploads some information into the table using device A user B can also find that information on the table on device B. Basically like this website. Someone posts a question, and it becomes synchronized and visible on other devices.

How is this done?

Nilanka Manoj
  • 3,527
  • 4
  • 17
  • 48
Azure
  • 127
  • 11
  • Huh? WHat do you mean by "device"? This question makes no sense. Sorry. – OldProgrammer Apr 28 '20 at 00:08
  • Yes, it is possible but you need to use XHR to submit data to your server and then websockets or similar on device B to see if any changes has happened and update accordingly – kunambi Apr 28 '20 at 00:09
  • Does this answer your question? [What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?](https://stackoverflow.com/questions/11077857/what-are-long-polling-websockets-server-sent-events-sse-and-comet) – frodo2975 Apr 28 '20 at 00:39
  • unfortunately, no – Azure Apr 28 '20 at 09:29

1 Answers1

1

you should have the main server to do so, simple solution is a polling mechanism :

client post:

function upload(){
  this.disabled = true
  postDataToRemoteServer({one:document.getElementById(“one”).value});
}

client poll:

setInterval(()=>getDatafromServer().then(data=>{
   document.getElementById(“one”).value = data.one
},1000)

server skeleton

@post
save(data){
  //save data to database <- postDataToRemoteServer calls this
}

@get
get(){
//get data from database <- getDatafromServer calls this

}

Nilanka Manoj
  • 3,527
  • 4
  • 17
  • 48