Changing Page Content without Reloading the Full Page

My client Santa Cruz Veterinary Hospital wanted to show several pages worth of information and I decided to use links on the right hand side that would dynamically load content into the center column:

Normally when you click a web page link then your browser blinks and you wait while new content is loaded. Using Ajax I was able to have only the center part of the page update when a link is clicked. Here’s the HTML for the link code:

I’m calling a javascript function named “ajaxpage” and passing it two fields:

  • oral-health.html (the new content to load)
  • page_text (the DIV name where the new content will load)

This javascript is defined in my file ajax-page.js which you can read and re-use. I got it initally from , a great resource.

In the center of my page I have a DIV statement where new content gets loaded into:

You may have noticed that this page uses Tables and are asking yourselves, “Why is Daniel still using tables in the era of CSS?”
Simple answer, I took over this site from another web developer and didn’t want to re-factor it and remove all tabels. Tables work, CSS works, use them both as needed.

This Post Has 2 Comments

  1. Les

    I tried to view your file ajax-page.js but it comes up as page not found when you click it. Can’t seem to find it on dynamicdrive either. Would you be able to email me a copy of this so I can try and adapt for my own situ?


  2. Daniel Payne

    Here’s the code:

    * Dynamic Ajax Content- © Dynamic Drive DHTML code library (
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at for full source code

    var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
    var loadedobjects=””
    var rootdomain=”http://”+window.location.hostname
    var bustcacheparameter=””

    function ajaxpage(url, containerid){
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
    try {
    page_request = new ActiveXObject(“Msxml2.XMLHTTP”)
    catch (e){
    page_request = new ActiveXObject(“Microsoft.XMLHTTP”)
    catch (e){}
    return false
    loadpage(page_request, containerid)
    if (bustcachevar) //if bust caching of external page
    bustcacheparameter=(url.indexOf(“?”)!=-1)? “&”+new Date().getTime() : “?”+new Date().getTime()‘GET’, url+bustcacheparameter, true)

    function loadpage(page_request, containerid){
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf(“http”)==-1))

    function loadobjs(){
    if (!document.getElementById)
    for (i=0; i

Leave a Reply