Hi folks,
I have a bit of a headache. I've finally added all the nice finishing touches to my own website (static only with a bit of DHTML).
Now I've just converted the whole thing to AJAX with a couple of simple functions and links changed here and there.
However, I want to create a really cool effect with my AJAX - which is I want to induce a "delay" so people actually see the "loading" section, cause at the moment, it's doing it at about 0.01ms and flashes across the screen before you have a chance to read it.
[CODE=javascript]
function GetXmlHttpObjec t() {
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.XMLHT TP");
}
}
return xmlHttp;
}
var myBodyAjax = new GetXmlHttpObjec t();
var myOCAjax = new GetXmlHttpObjec t();
var myURL, myParams, myMethod, myContainer, myWaitingContai ner, myAJObject
var thisAJ, thisCont, thisWaitCont
var myAJ, myCont, myWait
function doAjax(myURL, myParams, myMethod, myContainer, myWaitingContai ner, myAJObject) {
if (myAJObject==nu ll) {
alert ("Your browser does not support AJAX!");
return;
}
myAJObject.onre adystatechange= function(){stat eChanged(myAJOb ject, myContainer, myWaitingContai ner)};
switch (myMethod) {
case "get":
myAJObject.open ("GET",myURL+"? "+myParams,true );
myAJObject.send (null);
break;
case "post":
myAJObject.open ("POST",myURL,t rue);
myAJObject.send (myParams);
break;
default:
alert("AJAX data method not specified - please email webmaster@cmdev-associates.com" );
}
myAJObject.clos e;
}
function stateChanged(th isAJ, thisCont, thisWaitCont) {
switch (thisAJ.readySt ate) {
case 4:
var timer = setTimeout('fun ction(){showCon tent(thisAJ,thi sCont,thisWaitC ont)}',2000);
break;
default:
thisWaitCont.st yle.visibility = "visible";
}
}
function showContent(myA J, myCont, myWait) {
myWait.style.vi sibility='hidde n';
myCont.innerHTM L = myAJ.responseTe xt;
}
[/CODE]
The problem is happening at setTimeout - for whatever reason, it's not being called. I've tried taking the parameters out of quotes but they're AJAX and HTML objects and so aren't handled correctly, and I've used the function() part to force the setTimeout method to accept the function parameters, but still to no avail.
Any help would be much appreciated.
Many thanks,
Benjamin
I have a bit of a headache. I've finally added all the nice finishing touches to my own website (static only with a bit of DHTML).
Now I've just converted the whole thing to AJAX with a couple of simple functions and links changed here and there.
However, I want to create a really cool effect with my AJAX - which is I want to induce a "delay" so people actually see the "loading" section, cause at the moment, it's doing it at about 0.01ms and flashes across the screen before you have a chance to read it.
[CODE=javascript]
function GetXmlHttpObjec t() {
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.XMLHT TP");
}
}
return xmlHttp;
}
var myBodyAjax = new GetXmlHttpObjec t();
var myOCAjax = new GetXmlHttpObjec t();
var myURL, myParams, myMethod, myContainer, myWaitingContai ner, myAJObject
var thisAJ, thisCont, thisWaitCont
var myAJ, myCont, myWait
function doAjax(myURL, myParams, myMethod, myContainer, myWaitingContai ner, myAJObject) {
if (myAJObject==nu ll) {
alert ("Your browser does not support AJAX!");
return;
}
myAJObject.onre adystatechange= function(){stat eChanged(myAJOb ject, myContainer, myWaitingContai ner)};
switch (myMethod) {
case "get":
myAJObject.open ("GET",myURL+"? "+myParams,true );
myAJObject.send (null);
break;
case "post":
myAJObject.open ("POST",myURL,t rue);
myAJObject.send (myParams);
break;
default:
alert("AJAX data method not specified - please email webmaster@cmdev-associates.com" );
}
myAJObject.clos e;
}
function stateChanged(th isAJ, thisCont, thisWaitCont) {
switch (thisAJ.readySt ate) {
case 4:
var timer = setTimeout('fun ction(){showCon tent(thisAJ,thi sCont,thisWaitC ont)}',2000);
break;
default:
thisWaitCont.st yle.visibility = "visible";
}
}
function showContent(myA J, myCont, myWait) {
myWait.style.vi sibility='hidde n';
myCont.innerHTM L = myAJ.responseTe xt;
}
[/CODE]
The problem is happening at setTimeout - for whatever reason, it's not being called. I've tried taking the parameters out of quotes but they're AJAX and HTML objects and so aren't handled correctly, and I've used the function() part to force the setTimeout method to accept the function parameters, but still to no avail.
Any help would be much appreciated.
Many thanks,
Benjamin
Comment