Link to home
Start Free TrialLog in
Avatar of roblickley
roblickleyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to trigger multiple events using onload

I have a page which will be running in a dash board type style.
As a result of this I have used AJAX and DIV to split the page removing the need for the whole page to be reloaded each time something happens.
I need to get 2 DIV's preloaded with their pages onload - but can only get 1 or other to work at a time.
Code attached - I must be missing something but it is all standard stuff.

FYI - I can load entryMain or classStatus individually

If I call pageLoad in the body tag I get the output from the classStatus function in both divs?

On page I have an outer wrapper div and then the other two. I have checked and they are not nested within each other. For example (but not actually so no comments on the spelling relating to the script please!)

<div id="outerwrapper">
  <div id="classStatus">
  </div>
  <div id="mainContent">
  </div>
</div>

I have read through all the other articles I can find but no answers
function pageLoad()
{
	entryMain();
	classStatus();
	}
 
function entryMain()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="entry_main_div_default.asp";
url=url+"?sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged_main;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
 
function classStatus()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="class_status_div.asp";
url=url+"?sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged_status;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
 
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
 
 
function stateChanged_main() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("mainContent").innerHTML=xmlHttp.responseText;
}
}
 
function stateChanged_status() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("classStatus").innerHTML=xmlHttp.responseText;
}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of niko86
niko86

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of roblickley

ASKER

I prefer the latter option - I have tried setTimeOut and it doesnt work.

Where am I going wrong
function pageLoad()
	{
	
	entryMain();
	setTimeout("classStatus()", 3000);
	}

Open in new window