Isn't it generally a bad idea to parse all HTML as PHP? Here's another bad idea (though it can be fine if you don't use the highlighted update feature too much):
Code:
<!DOCTYPE html>
<html>
<head>
<title>Simple AJAX Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
#downloadcount {font: normal 95% verdana, arial, sans-serif;}
</style>
</head>
<body>
<div id="downloadcount">Number Downloaded: <span id="result"></span></div>
<script>
(function(url){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
document.getElementById('result').innerHTML = this.responseText;
}
};
xhttp.open('get', url + '?bust=' + new Date().getTime(), true);
xhttp.send();
setInterval(function(){
xhttp.open('get', url + '?bust=' + new Date().getTime(), true);
xhttp.send();
}, 3 * 60 * 1000);
})('counter.txt'); // use full path to counter.txt
</script>
</body>
</html>
If you don't need it updated, remove the highlighted. Currently it's set to update every 3 minutes, which is reasonable in most cases.
Bookmarks