Can anybody help me with this problem ? I am trying to display the array that I retrieve from PHP in HTML / Java form.
<?php
header("Content-Type: application/json; charset=UTF-8");
require('routeros_api.class.php');
$API = new routeros_api();
$API->debug = true;
$API->connect('1.1.1.1', 'admin', '123');
$API->write('/ip/firewall/filter/print');
$READ = $API->read(false);
$ARRAY = $API->parse_response($READ);
echo json_encode ($ARRAY);
$API->disconnect();
?>
output
[{ ".id":"*6", "chain":"unused-hs-chain", "action":"passthrough", "log":"false", "disabled":"true"},
{ ".id":"*5", "chain":"input", "action":"accept", "log":"false", "disabled":"true"},
{ ".id":"*2A", "chain":"unused-hs-chain", "action":"drop", "log":"false", "disabled":"true"}]
displayjava.html
<tbody id="myTable">
<script>
var xmlhttp = new XMLHttpRequest();
var url = "testdata2.php";
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
myFunction(xmlhttp.responseText);
}
}
xmlhttp.open("get", url, true);
xmlhttp.send();
function myFunction(response) {
var arr = JSON.parse(response);
var i;
var outp = "<tbody>";
for(i = 0; i < arr.length; i++) {
outp += "<tr>" +
"<td>" + arr[i].id + "</td>" +
"<td>" + arr[i].chain + "</td>" +
"<td>" + arr[i].action + "</td>" +
"<td>" + arr[i].log + "</td>" +
"<td>" + arr[i].disabled + "</td>" +
"</tr>";
}
outp += "</tbody>"
document.getElementById("myTable").innerHTML = outp;
}
</script>
</tbody>
By the way I am displaying the data in a table form format in html file
json_encodeso it handles the details for you.