I am able to print the current time picked (Input from JSON) using the code below.
However, I need to auto update the variable named j_time every second to show a clock. Please assist.
Note: I’ve read about setinterval. I am unable to successfully implement the same as the values collected for j_time is also passed to divcontent.
function onSuccess(data) {
var objItems = data.d.results;
var divContent = '<dl class="row" id="infoList">';
for (var i = 0; i < objItems.length; i++) {
var j_time = moment.tz(objItems[i].Timezone).format("DD/MM/YYYY HH:mm:ss (Z)");
console.log(j_time);
divContent += '<dt class="col-sm-3">Time</dt><dd class="col-sm-9">' + j_time + '</dd>';
}
$('#info').append(divContent);
}
2
Answers
How will you update j_time? Do you add local data incrementing its value or from the call that returns the JSON data you use?
in the first case, you can update the DOM like:
It’s not elegant and requires that you can delete and insert the elements every second… so to update only the date you could do something like:
If what you need is to get the JSON file every second, it may prove to be inefficient due to the network delay and whatnot…