Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / September 2005



Tip: Looking for answers? Try searching our database.

AJAX Loading Tab Doesn't Display

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
christopher.secord@gmail.com - 30 Sep 2005 20:37 GMT
I would like have a little "loading..." tab not unlike the one that
gmail uses and I would like to display that tab while an ajax call is
made.  The javascript to display the tab works.  The javascript to hide
the tab works.  But when I put the two together inside the function
that calls the ajax service, they don't work.

What seems to happen is that calls to change DOM object properties are
queued up, and then all executed simultaneously.  That's what it looks
like anyway.  Here is some example code:

<html>
<head>
<script language="Javascript">
    function showLoading () {
        document.getElementById("loading_tab").style.display = "";
    }
    function hideLoading () {
        document.getElementById("loading_tab").style.display = "none";
    }

    function ajax () {
        // show the loading tab
        showLoading ();

        // do cool ajax stuff (actual ajax code snipped)
        // (this code is just to waste some cpu cycles)
        for (var I = 0; I < 100000; I++) var X = new Date();

        // hide the loading tab
        hideLoading ();
    }
</script>
</head>
<body onload="hideLoading()">
<div style="background-color:#f00" id="loading_tab">loading...</div>

<form>
<input type=button value="Show Loading Tab" onclick="showLoading()">
<input type=button value="Hide Loading Tab" onclick="hideLoading()">
<input type=button value="Run AJAX Service" onclick="ajax()">
</form>

</body>
</html>
Matt Kruse - 30 Sep 2005 22:03 GMT
> What seems to happen is that calls to change DOM object properties are
> queued up, and then all executed simultaneously.

Some browsers, IE in particular, won't refresh the UI until a function
exits. So even though you're changing properties inside the function, these
are not shown until the whole function exits.

Instead, you need to look at setTimeout(). Run the first part to show the
tab, then use setTimeout() to run the second part in 10ms or something. The
first function will exit, and your changes will be shown. Then the second
will fire, etc.

Signature

Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com

christopher.secord@gmail.com - 30 Sep 2005 22:26 GMT
That fixes it.  thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.