Ajax Possibility?

I would like to know if it’s possible to load just a section by divs when using ajax. I currently have a working solution when I select an option from a form, and ajax loads the the index.cgi file into the div ‘siteinfo’. My index.cgi file has a number of functions that are ran with if elseif conditions. But the problem is that ajax is loading the whole page, header and all. I would like to strip everything and just have ajax load and display the contents between the ‘siteinfo’ divs.

Here’s my ajax.js code:


var xmlhttp;

function showSiteinfo(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="index.cgi";
url=url+"?site="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
document.getElementById("siteinfo").innerHTML = "<p align='center'><img src=bigrotation2.gif></p>";
if (xmlhttp.readyState==4)
{
document.getElementById("siteinfo").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}


Here’s some code snippet from index.cgi:


<select name='site' onchange='showSiteinfo(this.value)'>

Is what I’m trying to accomplish possible?

Thanks,

Golden

Instead of javascript stripping away everything thing it doesn’t need it would be better to let the server only send the info javascript needs.

  • Less bandwidth
  • Less server processing time
  • Less client processing time