I need an array of arrays. I have a ProcessWire page with pages and subpages and fields on those pages and subpages. I packed this information in an array of arrays like so…
<?php
$allarticles = $pages->find("template=article"); // find by template of the last level
$catalogue = array();
$i = 0;
foreach ($allarticles as $onearticle) {
$temp = array ( // create a temporary array for the lowest level
'id' => $onearticle->id,
'title' => $onearticle->title,
'coverimage' => $onearticle->cover->url,
'url' => $onearticle->url,
'author' => $onearticle->author,
'date' => $onearticle->date,
'year' => $onearticle->parent->parent->title,
'issue' => $onearticle->parent->title,
'offline' => $onearticle->offline,
'body' => $onearticle->body
);
$catalogue[$i] = $temp; // add the results of each foreach (i.e. an array) to the main array at position $i
$i++; // go to the next position of the main array
};
print_r ($catalogue);
?>
This seems to kind of work.
The code is in test.php which is in the root folder.
Now I'm trying to request this php-file via AJAX.
<script type="text/javascript">
var request = new XMLHttpRequest();
if (request) {
request.onreadystatechange = ReloadRequest;
request.open("GET", "test.php", true);
request.send(null);
}
function ReloadRequest() {
request.readyState;
var str = request.responseText;
document.getElementById("boxedcontent").innerHTML = (str);
}
</script>
This script is at the bottom of the template file that is applied to a specific page.
The js-code works when it requests an html file but it doesn't work with a php file. I receive an "(Internal Server Error) the server responded with a status of 500 ".
Thanks for help!