• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

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

0
roblickley
Asked:
roblickley
1 Solution
 
niko86Commented:
this happens because you are using one xmlHTTP Object for all calls, so the first onload call initiates the object, tries to call, then the second one fires and uses the same object, so the first call fails and the second is succeeding.
you need to do either two xmlHTTP objects or you do a function that does these two calls sequentially
0
 
roblickleyAuthor Commented:
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

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now