AJAX n00b. Bear with me.
I have an AJAX object requesting the date modified header of a file, and performing another function based on the result when the request returns ready state 4. This works.
Now I'd like to do the same thing to a series of files. This is where it breaks. I've tried creating separate request objects for each file checked (as suggested in some tutorials), but I haven't gotten it to work.
I don't even really know whether I can just create these objects and send these requests in close order via a loop, or if I need to have the next wait for the prior request to complete.
I've used the code below to compare one file's modification date between one interval and the next, and to reload content on a change. This seems to work, but I have to make it watch more than one file.
<html>
<head>
<script language="javascript" type="text/javascript">
var modified_bool = '';
var the_modified = '';
var the_modified_buffer = '';
function ajaxFunction() {
if (the_modified != the_modified_buffer) {
modified_bool = true;
}
else {
modified_bool = false;
}
var ajaxRequest;
try {
ajaxRequest = new XMLHttpRequest();
}
catch(e) {
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
try {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
alert("Problem");
return false;
}
}
}
ajaxRequest.onreadystatechange = function() {
if (ajaxRequest.readyState == 4) {
the_modified_buffer = the_modified;
the_modified = ajaxRequest.getResponseHeader("Last-Modified");
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.getResponseHeader("Last-Modified") + '<br />the_modified ' + the_modified + '<br />' + 'the_modified_buffer ' + the_modified_buffer + '<br />modified_bool ' + modified_bool;
var flash_display = document.getElementById('flash_div');
if (modified_bool == true) {
flash_display.innerHTML = '<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"804px\" height=\"768px\"><param name=\"movie\" value=\"test.swf"><param name=\"quality\" value=\"high\"><embed src=\"test.swf" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"804px\" height=\"768px\"></embed></object>';
}
}
}
ajaxRequest.open("HEAD", "watched.txt", true);
ajaxRequest.send(null);
}
</script>
</head>
<body>
<div id='ajaxDiv'>Loading...</div>
<script type="text/javascript">
window.setInterval("javascript:ajaxFunction()", 250);
</script>
<div id='flash_div'>Loading...
</div>
</body>
</html>