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. -
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;
-
}
-
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
3 5399
Hi all,
I solved the problem myself! I added a section of ASP code to my AJAX content-serving page: -
Dim startTime
-
startTime = Now()
-
Do While DateDiff("s",startTime,Now()) < 5
-
'Do absolutely nothing!
-
Loop
-
This made the page wait for exactly 5 seconds before continuing with processing ASP commands.
However, I'd still be very interested if anyone can provide a Javascript solution to the problem.
medicineworker
You may be looking for script.aculo.us.
Hi acoder,
Thanks for the link, but I'm not looking to use a JS library - I want to have control over my code and not be reliant upon third-party components to produce the functionality I require for (what should be) a relatively simple requirement.
Is there not just a simple way in JS of setting the AJAX stateChanged functions to be called after a pre-defined time delay?
Many thanks,
medicineworker
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve-O |
last post by:
The following code works great in FireFox, Opera, Netscape, Safari, and
Gecko, but NOT IE. Why?
I tried using 'native' js with setInterval and setTimeout, but I get
the same result. My IE...
|
by: quill |
last post by:
Hi
I am making a chatroom script and it appears that the problem seems to be that my setTimeout's are conflicting.
The logic is as follows:
Run a login check every x seconds
Run a trigger...
|
by: Nico VanHaaster |
last post by:
Hello all,
I have run across an issue with IE 6.0+. I have a page that makes an
XMLHttpRequest to the webserver to update a report on the page. The
first time you hit the refresh report button...
|
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= |
last post by:
Greetings! I was researching AJAX to provide a solution to displaying status
messages while a long process executed. I found several examples online and
was able to use their code to get a quick...
|
by: daokfella |
last post by:
I have a Webmethod in a server control which needs to be called using
AJAX. The control writes a javascript block that uses setTimeout to
call a an ajax js function after 10 seconds.
When...
|
by: mndprasad |
last post by:
Hi friends,
Am new to AJAX coding, In my program am going to have two texbox which going to implent AJAX from same table. One box is going to retrieve the value of other and vice...
|
by: lak |
last post by:
Hi friends,
I have to parse a XML file and when it is changed I need to change in
the front end.
If I use the settimeout() then it is working.
But I don't what to use the settimeout() function.
...
|
by: Bryan A |
last post by:
Is there a way to add a timeout to this script so that it times out at
a certain time. So it would be auto updating every 2seconds and it
would timeout like after 100 seconds with a message?.
...
|
by: petvampire |
last post by:
not sure if some one got a answer to this little issue. Im built a page that calls information from a page called database-update.asp and puts it in to the div tag Reload this. What i am trying to do...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |