i have tried to implement a counter for my site which was a free hosted one from 000a.biz using ajax.It has worked in my LOCALHOST But it doesnt worked in my server.
The html file is(main.htm):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Tcats Inc.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="ajax.js"></script>
</head>
<body onload="ajaxFunction()">
<font color="#000000" face="Arial, Helvetica, sans-serif">
<br><br><br><br><br><br>
     You are visitor number:
<b><span id="count"></span></b>
<br><br>You are viewing tcats.co.cc.The ultimate site for techies, hi-fi geeks and crazy coders <br><br><br><br>that provides forums which are technical in nature where you can submit your queries which will be answered by our expert panel.<br><br><br><br>Plz support us with feedbacks which we are always happy to hear.<br><br><br><br>So what are you waiting for,happy tcating!
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<hr>
©Tcats inc.All Rights Reserved.
</font>
</body>
</html>
The javascript file(ajax.js):
var xmlhttp
function ajaxFunction()
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET","counter.php",true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("count").innerHTML=xmlhttp.responseText;
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
The php file(counter.php):
<?php
$file=fopen("counter.txt","r+");
$count= fgets($file);
fclose($file);
$count++;
echo $count;
$file=fopen("counter.txt","r+");
fputs($file,$count);
fclose($file);
?>
I have also created a counter.txt file for saving the count.Some other ajax applications worked in the server but i dont know why its not working for this case.It is showing some error in the counter part while im accessing main.htm(the site is george.000a.biz/main.htm)
Somebody plz HELP...