I need some help to dynamically load data in a template as a file change. Below is a sample of the data and code
I have a json file:
data = '[{"name" : "bob", "value" : "3.1"}, {"name" : "joe", "value" : "5.6"}]';
The value in this file change regularly (every 2-3 sec)
I have an HTML file
<head>
<script type="text/javascript" src="data.json"></script>
<script type="text/javascript" src="javascript.js"></script>
</head>
<body>
<table>
<tr>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
</tr>
</table>
<body>
<script type="text/javascript">
document.body.innerHTML = markup;
</script>
And javascript.js is:
var mydata = JSON.parse(data);
const markup = `
<table>
<tr>
<td>${mydata[0].name}</td>
<td>${mydata[0].value}</td>
</tr>
<tr>
<td>${mydata[1].name}</td>
<td>${mydata[1].value}</td>
</tr>
</table>
`;
So the first question is: how can I get the data dynamically loading in the template as the value change? jQuery? node.js? I need the most simple solution as I am not a newbie.
And secondly, the html code is a bit more complex in reality, but is there a relatively simple way to loop through the data rather than me having to write everything manually? like introducing a "foreach d in data" ?
Thanks for your help, much appreciated!