So I got this website with PHP code that reads a file(that has JSON format) and then sends it to a javascript functions which prints it in a table. This works fine for me, but I want to press this button again so that I get an updated table, the file itself get's updated about each 30 minutes. This is my code:
index.php
<?php
function clean($string){
    return json_decode(rtrim(trim($string),','),true);
}
function getLog(){
    $logLines = file('../../../home/shares/flower_hum/humid.log');
    $entries = array_map("clean",$logLines);
    $finalOutput = ['log'  => $entries];
    $json = json_encode($finalOutput);
    return $json;
}
?>
<html>
    <head>
        <script src="script.js" type="text/javascript"></script>
        <script src="sorttable.js" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="style.css">
        <meta charset="UTF-8">
        <title>title</title>
    </head>
    <body>
        <button type="button" onclick='createTable(<?php getLog(); ?>)'>Generate log</button>
        <br><br>
        <div id="logDiv"></div>
    </body>
</html>
script.js
function createTable(jsonObject) {
//Removes existing tables if there is any.
var myNode = document.getElementById('logDiv');
    while (myNode.hasChildNodes()) {
            alert("logDiv has nodes, removing them now!")
            myNode.removeChild(myNode.firstChild);
    }
 //...Code that prints table
}
So If I press the button once, a table is generated, but If I press it again, nothing happends, even though the JSON file has been updated. If I refresh the page, it works again. I'm not sure why this isn't working as I expect it too. A new call to my php function getLog(); should read the file a new time and generate a new JSON Object.
 
    