First, I want to apologize if this is somewhere else. I'm looking for something simple. I have a PHP script that uses glob to retrieve a list of files from a directory. The directory is determined by a request sent though the address bar. ie. http://somewebsite.com/?loc=mydirectory I'm looking for a way to create a button that you can click on and the file list will display without refreshing the page. Here is the PHP code.
<?php
$BaseLoc='./';
$SecLoc='archives';
$FullLoc=$BaseLoc.$SecLoc.'/';
$loc=$_GET["loc"];
parse_str($_SERVER['QUERY_STRING'], $urlparams);
$GFloc=$urlparams['loc'];
function DirList() {
global $FullLoc;
$DirList=glob($FullLoc.'*',GLOB_ONLYDIR);
foreach ($DirList as $dirlist) {
$edl=explode ('/',$dirlist);
$dirlist=end($edl);
echo '<li><a href="?loc='.$dirlist.'">'.$dirlist.'</a></li>';
}
}
function ListFiles($GFloc){
global $FullLoc,$GFloc;
$FileLoc=$FullLoc.$GFloc;
$FileList=glob($FileLoc.'/*');
foreach ($FileList as $filelist) {
echo $filelist.' - '.$GFloc.'<br />';
}
}
?>
keep in mind that this is a test project for the purposes of getting a handle on how to do this type of AJAX. I know there is some Jquery with .get and I could have sworn I'd done this before but for the life of me I just can't seem to wrap my head around it. I know it's got to be something simple with a button click and then write the result into a div. Any help would be appreciated or even a link to an answer that I missed. Thanks.
I'm editing this on 1-28-2017 to try and clarify what I'm attempting to do. With the current php code above. When this .php page is visited it generates a list of sub-folders inside a folder and turns that list into clickable links. Inside each of those sub-folders is a group of media files. Currently if I click on one of the now generated sub-folder links. The entire page refreshes and I get a display of all the files inside that sub-folder. This is done by using php get and a variable inside the url. The only thing I 'm trying to change is that I get the same result, without refreshing the page. If you want to see an example of this functionality as it currently is, you can go to my test page. http://testbed.myreth024.tk/ajax/ I keep thinking it's something simple with the jquery .get. I just can't seem to find a good example of how to pass those url parameters through. Anyway. Thanks again for all the responses.