Hey,
In the following code the function showdivs() is called on body load, though only the second div is loaded. I've been searching on the web for similar problems and I know it has to do with the handler function, which is supposed to be run twice but now just cancels the first function as soon as the second one is called. Could anybody explain me how to solve this?
TIA,
Woods
In the following code the function showdivs() is called on body load, though only the second div is loaded. I've been searching on the web for similar problems and I know it has to do with the handler function, which is supposed to be run twice but now just cancels the first function as soon as the second one is called. Could anybody explain me how to solve this?
TIA,
Woods
Code:
var time_variable;
function getXMLObject() //XML OBJECT
{
var xobject = false;
try {
xobject = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers
}
catch (e) {
try {
xobject = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+
}
catch (e2) {
xobject = false // No Browser accepts the XMLHTTP Object then false
}
}
if (!xobject && typeof XMLHttpRequest != 'undefined') {
xobject = new XMLHttpRequest(); //For Mozilla, Opera Browsers
}
return xobject; // Mandatory Statement returning the ajax object created
}
var xobject = new getXMLObject(); //xmlhttp holds the ajax object
function handler() {
var getdate = new Date();
if(xobject) {
xobject.open("POST",phpFile,true);
xobject.onreadystatechange = function() {
if (xobject.readyState==4) {
if(xobject.status == 200) {
document.getElementById(divID).innerHTML=xobject.responseText;
}
else {
alert('error');
}
}
}
xobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xobject.send(postVars);
}
}
function showdiv1() {
divID = "div1"; //define html div
phpFile = "showdiv1.php"; //define file to be loaded
postVars = "null"; //define post vars
new handler();
}
function showdiv2() {
divID = "div2"; //define html div
phpFile = "showdiv2.php"; //define file to be loaded
postVars = "null"; //define post vars
new handler();
}
function showdivs() {
showdiv1();
showdiv2();
}
Comment