How can I use getjson to parse a php output?
I am totally lost when it come to json/ajax stuff (I guess I am just too old).
I have a php file (preload.php) which reads:
-
<?php
/* Read all files from directory */
$ImageDirectory = ($_GET['directory']);
$ImageDirectory = dir($ImageDirectory);
$ImageArray = array();
/* Store imagefiles in an array */
while($ImageLoop = $ImageDirectory->read())
{
if (isImage($ImageLoop)) {
$ImageArray[] = $ImageLoop;
}
}
/* Is the file an image? */
function isImage($FileLoop) {
return preg_match('/^.+\.(gif|png|jpe?g|bmp|tif)$/i', $FileLoop);
}
/* Return the array contents */
echo $ImageArray;
?>
And a Javascript function:
-
function PreLoadImages(ImageDir) {
for(var counter = 0; counter<ImageDir.length; counter++) {
ImageObject = new Image();
ImageObject.src = ImageDir[counter];
}
}
This JS is in an external (.js) file. Obviously I want the argument ImageDir to be read from the php file. I suspect I have to use $.getjson, but am too stupid to know how.
Any help would be much appreciated.