Dynamically loading content onto a page?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thetechgeek
    New Member
    • Nov 2007
    • 6

    Dynamically loading content onto a page?

    hey all,
    I'm a bit new to AJAX, and I was wondering how I could dynamically load content onto a page to prevent the user from having to reload the entire page, they'd just have to load the main content section that they want. Here's a page that I got my inspiration for this from: http://library.thinkquest.org/06aug/02048/. Try clicking on one of the tabs above the main content. You'll see a loading screen come up for a second, and then the new content will pop up. I was wondering if I could perhaps do this through frames? Is this the reccomended way to do this?
    Just wanting some opinions. (and perhaps some help with AJAX once I get started on this)

    Thanks.
  • rnd me
    Recognized Expert Contributor
    • Jun 2007
    • 427

    #2
    you can use frames. you could also load the content to a script variable and then inject it into page using .innerHTML.


    Code:
    function IOStr(U){
    X=((!window.XMLHttpRequest)?new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest);
    X.open('GET',U,!!0);
    X.send('');	
    return X.responseText;
    }
    
    function el(tid) {
        return document.getElementById(tid);
    }

    using above functions as a code bank, inject "myDetails. htm" into a <div> tag with an id of details.
    Code:
    el("details").innerHTML=IOstr('myDetails.htm');

    Comment

    • thetechgeek
      New Member
      • Nov 2007
      • 6

      #3
      Ah, ok.
      Hmm... It would be useful if I could display "loading... " while the content is being loaded. How would this be possible?

      Thanks.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Use a span/div which contains the loading text and keep it hidden (style="display :none" or style="visibili ty:hidden") and then display before making the Ajax call (divElem.style. display = 'block') and then hide it again once complete.

        Comment

        Working...