Results 1 to 2 of 2

Thread: Animated circle while loading page.

  1. #1
    Join Date
    Jun 2005
    Location
    Portugal
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Animated circle while loading page.

    Hi

    On some sites I see an animated circle when waiting for the next page to load. Is there a sample jscript about how to do this?

    Carlos

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Are you looking for something in AJAX or just something with the loading image in general. If you were using AJAX, here is a simple code snippet that you can use:

    (Place between the <head> tags):
    Code:
    <script type="text/javascript">
    var url = "test.php";
    var XMLHttpRequestObject = false;
    
    if (window.XMLHttpRequest) {
    XMLHttpRequestObject = new XMLHttpRequest();
    } 
    
    else if (window.ActiveXObject) {
    XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHttp");
    }
    
    if(XMLHttpRequestObject) {
    var obj = document.getElementById("div-id-here");
    XMLHttpRequestObject.open("GET", url);
    XMLHttpRequestObject.onreadystatechange = function()
    {
    if (XMLHttpRequestObject.readyState == 4 &&
    XMLHttpRequestObject.status == 200) {
    obj.innerHTML = XMLHttpRequestObject.responseText;
    }
    
    else {
    obj.innerHTML = '<img src="loading.gif"> Loading';
    }
    
    }
    XMLHttpRequestObject.send(null);
    }
    
    </script>
    test.php:

    Code:
    <?php 
    
    echo 'Hello World!';
    
    ?>
    and loading.gif is attached below.

    Hope this helps.

    EDIT: You can get more animated "loading" images by going to AJAXload.info
    Last edited by thetestingsite; 03-22-2007 at 03:21 AM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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
  •