从json文件自动填充表

I have a basic table, that reads data from a json file to fill the rows This fill is updated by a 3rd party application, and I'd need to add new rows automatically, without the viewer having to refresh the page. Mostly I'm looking for tutorials or some such on how to accomplish this. Thanks in advance for any advice!

$strJsonFileContents = file_get_contents("./includes/dispatch.json");
$mdt = json_decode($strJsonFileContents, true);
?>
<div id="callboard">
    <div align="center">
            Call ID: <input type="text" id="AlertId" class="mdt" size="10" readonly  />
            Type: <input type="text" id="AlertType" class="mdt" size="10" readonly  />
            Location: <input type="text" id="AlertLocation" class="mdt" size="25" readonly  />
            Status: <input type="text" id="AlertStatus" class="mdt" size="10" readonly  />
            Units: <input type="text" id="AlertUnits" class="mdt" size="20" readonly  /><hr><span id='ct' ></span><hr>
    </div>
<hr>
    <h3>Active Calls</h3>
    <table id="mdt-table">
    <tr onclick="javascript:showRow(this);">
    <th>Call ID</th>
    <th>Type</th>
    <th>Caller</th>
    <th>Location</th>
    <th>Details</th>
    <th>Status</th>
    <th colspan="2">Units</th>
    <th>Other Info</th></tr>
    <?php
    $arrlength = count($mdt);
    for ($x = 0; $x < $arrlength; $x++)
            {
            if ($mdt[$x][AlertType]=='10-13')
                    {
                    echo "<tr class=\"blinking\" onclick=\"javascript:showRow(this);\">";
                    }
            else { echo "<tr onclick=\"javascript:showRow(this);\">";
                    }
            echo "<td name=\"AlertId\">". $mdt[$x][AlertID]; echo "</td>";
            echo "<td name=\"AlertType\">". $mdt[$x][AlertType]; echo "</td>";
            echo "<td name=\"AlertCaller\">". $mdt[$x][AlertCaller]; echo "</td>";
            echo "<td name=\"AlertLocation\">". $mdt[$x][AlertLocation]; echo "</td>";
            echo "<td name=\"AlertMessage\">". $mdt[$x][AlertMessage]; echo "</td>";
            echo "<td name=\"AlertStatus\">". $mdt[$x][AlertStatus]; echo "</td>";
            echo "<td name=\"AlertUnits\" colspan=\"2\">". $mdt[$x][AlertUnits]; echo "</td>";
            echo "<td name=\"AlertOther\">". $mdt[$x][AlertOther]; echo "</td>";
            echo "</tr>";
            }
?>
    </table>

When you grab the JSON data, specifically the string, you can use the PHP function json_decode($raw_json_string) that will return an associative array ( if js object ) or just a regular array ( js array )

if you want to fetch JSON data for javascript, you can use the php function

json_encode($array); that will return a string ready to use in Javascript as an object variable.

so if you want to use a JSON object in PHP....

php:

`

$raw_json_string = {data: 2, data2:"hello world", data3:[1,2,3,4],};
$array = json_decode($raw_json_string);

$array['data'] == 2; // true

$array['data2'] == "hello world"; // true 

$array['data3'] == [1,2,3,4]; // true`

then you can use this array and loop through it to create your HTML table rows.

hope this helps.