
June 10th, 2008, 06:46 PM
|
|
Registered User
|
|
Join Date: Jun 2008
Posts: 2
Time spent in forums: 15 m 50 sec
Reputation Power: 0
|
|
|
yes. its a dynamic website with a database.
Quote: | Originally Posted by ChiefWigs1982 Ok, I'll bite. Let's see it.
You realise that you can't actually use JavaScript on it's own for
counting hits - it is only a client side scripting language - it has
no way of storing the data gathered. |
Yes. its a dynamic website with a database. Thanks for your help!
Here is the code:
Code:
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject()
{
var xmlHttp;
try
{ xmlHttp = new XMLHttpRequest(); }
catch(e)
{
var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
"MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP");
for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
{
try { xmlHttp = new ActiveXObject(XmlHttpVersions[i]); }
catch (e) { }
}
}
//xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
if (!xmlHttp) { return; }
else { return xmlHttp; }
}
function showCount()
{
if (xmlHttp)
{
try
{
xmlHttp.open("GET", "../count.txt?sid=" + Math.random(), true);
xmlHttp.onreadystatechange = handleRequestStateChange;
xmlHttp.send(null);
}
catch (e) { return; }
}
}
function showCountSec()
{
if (xmlHttp)
{
try
{
xmlHttp.open("GET", "../count.txt?sid=" + Math.random(), true);
xmlHttp.onreadystatechange = handleRequestStateChangeSec;
xmlHttp.send(null);
}
catch (e) { return; }
}
}
function handleRequestStateChange()
{
myDiv = document.getElementById('counter');
var response = '';
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
try
{
response = xmlHttp.responseText;
myDiv.innerHTML = formatCommas(response);
}
catch(e) { return; }
}
else { return false; }
}
}
function handleRequestStateChangeSec()
{
myDiv = document.getElementById('sDoc');
var response = '';
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
try
{
response = xmlHttp.responseText;
myDiv.innerHTML = formatCommas(response);
}
catch(e) { return; }
}
else { return false; }
}
}
function uncache(url)
{
var d = new Date();
var time = d.getTime();
return url + '&time='+time;
}
function formatCommas(numString)
{
var re = /(-?\d+)(\d{3})/;
while (re.test(numString)) { numString = numString.replace(re, "$1,$2"); }
return numString;
}
Last edited by mehere : June 10th, 2008 at 08:46 PM.
Reason: added code tags ... please use [code][/code] tags in the future.
|