I’m VERY new to Javascript but I am trying to implement the [COLOR=Red]XMLHttpRequest[B]synch[B]async
So the below code works synchronously and because only one request is returned at a time, then the next it does not foul up multiple simultaneous calls to the same functions. I’m looking for a savior so I can effectively implement this the way it was supposed to work. Code below:
[B]JAVASCRIPT FILE:
function createRequestObject() {
var req;
if(window.XMLHttpRequest){
// Firefox, Safari, Opera…
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
// Internet Explorer 5+
req = new ActiveXObject(“Microsoft.XMLHTTP”);
} else {
// There is an error creating the object,
// just as an old browser is being used.
alert(‘There was a problem creating the XMLHttpRequest object’);
}
return req;
}
function handleDivTag(divtag)
{
var divtag;
return divtag;
}
function handleTimeOut(timeout)
{
var timeout;
return timeout;
}
function handleRefresh(refresh)
{
var refresh;
return refresh;
}
// Make the XMLHttpRequest object
var http = createRequestObject();
// Create the Divtag Handler — Mainly an IE 6 Fix
var divhandler = new handleDivTag(null);
var timehandler = new handleTimeOut(null);
var refreshhandler = new handleRefresh(null);
function sendRequest(act,divtag,timeout,refresh)
{
// Open PHP script for requests in sycnhronous mode
http.open(‘get’, act, [COLOR=Red]0[/COLOR]);
http.onreadystatechange = function () { handleResponse(); }
divhandler.divtag = divtag;
timehandler.timeout = timeout;
refreshhandler.refresh = refresh;
http.send(null);
}
function handleResponse()
{
if(http.readyState == 4 && http.status == 200)
{
// Text returned FROM PHP script
var response = http.responseText;
// document.write(http.responseText);
if(response)
{
// UPDATE ajaxTest content
document.getElementById(divhandler.divtag).innerHTML = response;
setTimeout(timehandler.timeout,refreshhandler.refresh);
}
}
}
function news() {sendRequest(‘/ping/panel_c_news’,’news’,news,120000);}
function blogs() {sendRequest(‘/ping/panel_c_blogs’,’blogs’,blogs,300000);}
function activities() {sendRequest(‘/ping/panel_c_activities’,’activities’,activities,60000);}
//function whoswho() {sendRequest(‘/ping/panel_c_whoenss_downloads’,’whoswho’,whoswho,600000);}
function whosonline() {sendRequest(‘/ping/panel_l_whosonline’,’whosonline’,whosonline,30000);}
function whosout() {sendRequest(‘/ping/panel_l_whosout’,’whosout’,whosout,60000);}
[B]MY FUNCTIONS CALLS FROM MY HTML FILE:
<script language=”JavaScript”>
function LoadFuncs()
{ news();blogs();activities();whosonline();whosout() }
</script>
<BODY onload=”LoadFuncs()”>