I'm fairly new to JavaScript and I've been hunting around for a solution for this problem:
I have names and numbers being written to a data.json file in the same directory as my JavaScript file. What I'm looking for is every few minutes to check that data.json and update my HTML p tag with the changes.
My HTML block looks like this:
...
<body>
<p id="mydata">
</p>
</body>
...
My data.json looks like this:
[{"Name":"Charlie","Number":"5"},{"Name":"Patrick","Number":"3"}]
My Javascript block looks like this:
...
setInterval(function(){
var json = // read in json file
//this is the part I'm missing
document.getElementById('mydata').innerHTML = json;
},300000); // every 5 minutes
$.getJSON will load local json file
setInterval(function(){
$.getJSON("yourjsonfile.json", function(json) {
console.log(json);
document.getElementById('mydata').innerHTML = json;
});
},300000); // every 5 minutes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With