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 5480
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 security settings are not an issue.
Anyone have any insight on this?
Thanks!
-sh
|
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
|
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...
|
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...
|
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:...
| |
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;
|
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?
|
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')
{
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |