Results 1 to 4 of 4

Thread: Help please: How to add a "Please wait ." message in my inner page

  1. #1
    Join Date
    Feb 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help please: How to add a "Please wait ." message in my inner page

    Hi,

    I've been stuck here over one week.

    I need to dynamically update an inner part of my page, during the updating, I want this area to show a "Please wait..." massage and a spinning image. And after the area finishes updating by new content, the 'Please wait' msg and the spinning wait image will disappear. The following is an example I made -- when clicking the "Replace Text" link, "Hello World" will be replaced by a list box which contains database data. But it is not working correctly: when I click the link, the wait message and the spinning wait image appear, but after all the update finishes, the wait message and the image are still there (they are supposed to disappear). What's wrong with my code? Can anybody give me a correct example?

    Thank you very much!

    Ajax.html------------------------------

    <script type="text/javascript">
    var http = false;

    if(navigator.appName == "Microsoft Internet Explorer") {
    http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
    http = new XMLHttpRequest();
    }

    function replace() {
    http.open("GET", "rpc.php", true);
    http.onreadystatechange=function() {
    if(http.readyState == 4) {
    document.getElementById('foo').innerHTML = http.responseText;
    }
    }
    http.send(null);
    }
    </script>

    <p><a href="javascript:replace()">Replace Text</a></p>

    <div id="foo">
    Hello, world!

    </div>

    rpc.php----------------------------------------------

    <?php

    $dbhost = "localhost";
    $dbuser = "fossilplot";
    $dbpass = "fossilplot";
    $dbname = "fossilplot";
    mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($dbname) or die(mysql_error());
    $result = mysql_query("select * from genus");

    echo "<div id=\"hidelater\"><img src=\"loading.gif\"> Please Wait, loading
    data...</div>";
    ob_flush(); flush();

    echo "<select name=\"sel\" multiple size=\"63\">";

    while ($row = mysql_fetch_array($result)) {
    echo "<option>".$row{'genus_name'}."</option>";
    }

    echo "</select>";

    echo "<script>document.getElementById(\"hidelater\").style.display = 'none';
    </script>";

    ?>

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Replace:
    Code:
    http.onreadystatechange=function() {
    if(http.readyState == 4) {
    document.getElementById('foo').innerHTML = http.responseText;
    }
    }
    With:
    Code:
    http.onreadystatechange=function() {
    if(http.readyState == 4) {
    document.getElementById('foo').innerHTML = http.responseText;
    } else {
    var a = document.createElement("img");
    a.src = "loading.png";
    document.getElementById('foo').appendChild(a);
    }
    I'm new to the DOM kinda stuff.... I don't know if it will work.
    Jeremy | jfein.net

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    You may have to include this as well:
    Code:
    if (http.status == 200) document.getElementById('foo').innerHTML = http.responseText;
    - Mike

  4. #4
    Join Date
    Feb 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •