Kadjo

SoftDev Journal

About This Journal

24 June 2007 by Jojo Makiling

Technical concerns tend to find a solution as long as there are good people working on them. And Linux has the very best. - Linus Torvalds

Short note of Javascript refresher

September 28th, 2009 by pepesmith

In the program i made, which tabulates the latest 20 call in a minute, I’ve found some good resource for it.
My setup, perl-cgi script is the one that generates the list of calls. This script is just called via an Ajax function.

The main important part of that is part that contains this setInterval.
I chose setInterval since the “Call Accounting System” i made needs a refreshing every minute to update
the user about the activity of PBX.

The code also requires to have an id “content” to have the content generated by “refresher.cgi” displayed.
An example of usage will be.

<div id=”content”>&nbsp;</div>

and i put the code at the bottom of the html page.

<script type=”text/javascript” src=”20records.js”></script>

Below is the content of the 20records.js file:

var xmlhttp;

function showList()
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="refresher.cgi";
url=url+"?sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{

document.getElementById('content').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;
}
window.setInterval("showList();",60000)

Posted in Miscellaneous | No Comments »

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.