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.
Expand|Select|Wrap|Line Numbers
- 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;
- }
- var myBodyAjax = new GetXmlHttpObject();
- var myOCAjax = new GetXmlHttpObject();
- var myURL, myParams, myMethod, myContainer, myWaitingContainer, myAJObject
- var thisAJ, thisCont, thisWaitCont
- var myAJ, myCont, myWait
- function doAjax(myURL, myParams, myMethod, myContainer, myWaitingContainer, myAJObject) {
- if (myAJObject==null) {
- alert ("Your browser does not support AJAX!");
- return;
- }
- myAJObject.onreadystatechange=function(){stateChanged(myAJObject, myContainer, myWaitingContainer)};
- switch (myMethod) {
- case "get":
- myAJObject.open("GET",myURL+"?"+myParams,true);
- myAJObject.send(null);
- break;
- case "post":
- myAJObject.open("POST",myURL,true);
- myAJObject.send(myParams);
- break;
- default:
- alert("AJAX data method not specified - please email webmaster@cmdev-associates.com");
- }
- myAJObject.close;
- }
- function stateChanged(thisAJ, thisCont, thisWaitCont) {
- switch (thisAJ.readyState) {
- case 4:
- var timer = setTimeout('function(){showContent(thisAJ,thisCont,thisWaitCont)}',2000);
- break;
- default:
- thisWaitCont.style.visibility = "visible";
- }
- }
- function showContent(myAJ, myCont, myWait) {
- myWait.style.visibility='hidden';
- myCont.innerHTML = myAJ.responseText;
- }
Any help would be much appreciated.
Many thanks,
Benjamin