473,796 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AJAX setTimeout

JamieHowarth0
533 Recognized Expert Contributor
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.

Expand|Select|Wrap|Line Numbers
  1. function GetXmlHttpObject() {
  2. var xmlHttp=null;
  3. try {
  4.     // Firefox, Opera 8.0+, Safari
  5.     xmlHttp=new XMLHttpRequest();
  6. } catch (e) {
  7.     // Internet Explorer
  8.     try {
  9.         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  10.     } catch (e) {
  11.         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  12.     }
  13. }
  14. return xmlHttp;
  15. }
  16.  
  17. var myBodyAjax = new GetXmlHttpObject();
  18. var myOCAjax = new GetXmlHttpObject();
  19. var myURL, myParams, myMethod, myContainer, myWaitingContainer, myAJObject
  20. var thisAJ, thisCont, thisWaitCont
  21. var myAJ, myCont, myWait
  22.  
  23. function doAjax(myURL, myParams, myMethod, myContainer, myWaitingContainer, myAJObject) {
  24. if (myAJObject==null) {
  25.     alert ("Your browser does not support AJAX!");
  26.     return;
  27. }
  28. myAJObject.onreadystatechange=function(){stateChanged(myAJObject, myContainer, myWaitingContainer)};
  29. switch (myMethod) {
  30.     case "get":
  31.         myAJObject.open("GET",myURL+"?"+myParams,true);
  32.         myAJObject.send(null);
  33.         break;
  34.     case "post":
  35.         myAJObject.open("POST",myURL,true);
  36.         myAJObject.send(myParams);
  37.         break;
  38.     default:
  39.         alert("AJAX data method not specified - please email webmaster@cmdev-associates.com");
  40. }
  41. myAJObject.close;
  42. }
  43.  
  44. function stateChanged(thisAJ, thisCont, thisWaitCont) {
  45. switch (thisAJ.readyState) {
  46.     case 4:
  47.         var timer = setTimeout('function(){showContent(thisAJ,thisCont,thisWaitCont)}',2000);
  48.         break;
  49.     default:
  50.         thisWaitCont.style.visibility = "visible";
  51. }
  52. }
  53.  
  54. function showContent(myAJ, myCont, myWait) {
  55.     myWait.style.visibility='hidden';
  56.     myCont.innerHTML = myAJ.responseText;
  57. }
  58.  
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
Sep 14 '07 #1
3 5480
JamieHowarth0
533 Recognized Expert Contributor
Hi all,

I solved the problem myself! I added a section of ASP code to my AJAX content-serving page:
Expand|Select|Wrap|Line Numbers
  1. Dim startTime
  2. startTime = Now()
  3. Do While DateDiff("s",startTime,Now()) < 5
  4.        'Do absolutely nothing!
  5. Loop
  6.  
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
Sep 14 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
You may be looking for script.aculo.us.
Sep 14 '07 #3
JamieHowarth0
533 Recognized Expert Contributor
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
Sep 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

17
3157
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 security settings are not an issue. Anyone have any insight on this? Thanks! -sh
1
2919
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 check every x seconds
6
2547
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 the data is refreshed, however if you try to refresh the report the onreadystatechage does not seem to fire. I have tested this by placing an alert in the verifyID2 & verifyID3 function to track where the XMLHttpRequest currently is. Now when...
6
5169
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 application working. However, when attempting to implement the solution, the AJAX calls weren't updating the screen like the examples were and seemed not to fire until after the long running process had completed. I found the only real...
1
2207
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 developing (not using a server control) on an aspx page, this worked great. I set the EnablePageMethods() to true on the ScriptManager. The method was marked as WebMethod in the page class. Thus, I could call the ajax method like this:...
2
4678
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 versa. I have implemented successfully for one text box, but it's done for the other field, since am getting script errors. <script> var queryField; var lookupURL; var divName;
4
1590
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. Is there any other way to do that?
20
2242
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?. Heres my code: var xmlhttp = false ; if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
1
2768
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 is make a pop up so if some one clicks the link shown it open a pop up window. When trying to do this nothing happens. Any ideas how i can get a pop up window. I be Honest i do not understand ajax as im just using it as a refresh method to get new...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9524
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.