Page 1 of 1

load content in div tag withouth page reload

Posted: Wed Dec 21, 2005 7:38 pm
by kendall
hey guys,

i found this script that would load external source content into a div tag without reloading a page but i dunno....the IE version doesnt seem to work
the php file echos a random record from a database

Code: Select all

<html>
<head>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="Mon, 22 Jul 2002 11:12:01 GMT">
<script type="text/javascript">
var xmlhttp

function loadXMLDoc(url)
{
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange=state_Change
    xmlhttp.open("GET",url,true)
    xmlhttp.send();
    }
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
  {
  document.getElementById('T1').innerHTML=xmlhttp.responseText
  }
  else
  {
  alert("Problem retrieving data:" + xmlhttp.statusText)
  }
  }
}

</script>
</head>

<body onload="loadXMLDoc('hot_tips_random_test.php')">
<div id="T1" style="border:1px solid black"></div><br />
<a href="#" onClick="javascript: loadXMLDoc('hot_tips_random_test.php')">Next Tip</a>
</body>

</html>
what do you guys make of it? it doesnt return any warning or errors
works perfect with firefox

Kendall