JSON example:
[{
"client": "client1",
"ip": "127.0.0.1",
"status": "up"
}, {
"client": "client2",
"ip": "127.0.0.2",
"status": "up"
}]
I have this script to read the JSON file and create tables and apply color to tables according to JSON information:
<script type="text/javascript">
$.getJSON("<urltojson>/clients.json",
function (data) {
var tr;
for (var i = 0; i < data.length; i++) {
tr = $('<tr/>');
tr.append("<td>" + data[i].client + "</td>");
$('table').append(tr);
if(data[i].status == "up")
{
$('td',tr).css ('background-color', '#88d066');
} else {
$('td',tr).addClass("statusHOSTDOWN");
};
}
});
</script>
The JSON file itself gets updated through a backend python script. Everything works as intended. However, if I want to see update information from JSON file I need to hard-reload the webpage, which is pretty easy to do. But I want javascript to auto reload JSON in the background and apply conditions gracefully without a hard reload of the webpage.
It's probably something trivial to do , but my lack of js knowledge is not helping me. I did a couple of hours worth research without any luck. Any help is appreciated.