This JavaScript program shows how to fetch a PHP generated JSON object via an AJAX call.
<!DOCTYPE html>
<html>
<head>
<title>XoaX.net: PHP JSON</title>
<link rel="icon" href="data:,">
</head>
<body>
<script language="javascript" type="text/javascript">
let qHttpRequest = new XMLHttpRequest();
// Method, URL, Async
qHttpRequest.open( "GET", "ReturnJson.php", true );
qHttpRequest.onload = function( e ) {
let qOutputElement = document.getElementById("idText");
qOutputElement.innerHTML = this.response;
};
qHttpRequest.send();
</script>
<pre id="idText"></pre>
</body>
</html>
<?php
header('Content-type: text/javascript');
$qGod = array(
"Father"=>
array("Maker"=>
array("Heaven","Earth", "All things visible", "All things invisible"),
),
"Son"=>
array(
"One Lord Jesus Christ",
"Only begotten Son of God",
"Born"=>array("Of the Father","Before all Ages"),
"True God from true God",
"Begotten",
"Not Made",
"Consubstantial with the Father",
"Came down from Heaven"=>array("For us men", "For our salvation"),
"By the Holy Spirit"=>array("Was incarnate of the virgin Mary", "Became man"),
"For our sake"=>array("He was crucified under Pontius Pilate", "He suffered death and was buried", "He rose again on the third day"),
"He ascended into Heaven"=>array("He is seated at the right hand of the Father"),
"He will come again"=>array("To judge the living and the dead", "His kingdom will have no end")
),
"Holy Spirit"=>array("The Lord, the giver of life",
"Proceeds"=>array("From the Father", "From the Son"),
"Adored and glorified"=>array("With the Father", "With the Son"),
"Has spoken through the prophets"
)
);
echo json_encode($qGod, JSON_PRETTY_PRINT);
?>
© 20072026 XoaX.net LLC. All rights reserved.