I have a test page that I keep all my labs on on my local IDE (MAMP). I recently wrote a small php script that will read the directory and create a link of each file in that directory which is help to me as now i don't have to write out the full local url each time to test a new file. I still have to refresh the page though every time i create a new file so its' read. I wanted to set the page to being 'self-reading' so that when i add something, it would appear on the page. I thought Ajax would be a good use of this but the script i tried doesn't work. I've no knowledge of ajax and or jQuery - i'm a super newb honestly - but i'm trying to grow.
My problem in a nut shell: The script does not appear to update the page (maybe it is and i'm not doing it right? I don't know - maybe i ought to be using javascript to refresh the page?)
my code:
<!-- For ease of use, use JQuery hosted lib- you can download any version and link to it locally also -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
$("#responsecontainer").load("response.php");
var refreshId = setInterval(function() {
$("#responsecontainer").load('response.php?randval='+ Math.random());
}, 1000);
$.ajaxSetup({ cache: false });
});
</script>
<div id="responsecontainer">
<?php //index.php
$dir_open = opendir('.');
while(false !== ($filename = readdir($dir_open))){
if($filename != "." && $filename != ".."){
$link = "<a href='./$filename' target='_blank'> $filename </a><br />";
echo $link;
}
}
closedir($dir_open);
?>
</div>
<!-- End jQuery auto update div -->