hi,
i am having a problem getting my AJAX to work…
what i want it to do is do the function on page load, the refresh the data every second, i have messed about with the code but cannot seem to get it to do what i want…it loads the function fine on page load, but it wont refresh…
can some one please help me with this.
[CODE]
<?php
include(‘connect.php’);
$con = mysql_connect(“$server”,”$user”,”$pass”);
if (!$con) {
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db(“$db”, $con);
$sql=”SELECT * FROM users WHERE accessid = “.$_GET[‘user’];
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
?>
<body onload=”showDetails(<?php echo $row[‘username’]; ?>)” />
<script type=”text/javascript”>
var xmlHttp
function showDetails(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert (“Your browser does not support AJAX!”);
return;
}
var url=”userinfo.php”;
url=url+”?q=”+str;
url=url+”&sid=”+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open(“GET”,url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==1)
{
document.getElementById(“txtHint”).innerHTML==”Loading”;
}
if (xmlHttp.readyState==4)
{
document.getElementById(“txtHint”).innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e)
{
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
}
return xmlHttp;
}
setTimeout(“showDetails(<?php echo $row[‘username’]; ?>)”, 100);
</script>
<span id=”txtHint”>
</span>
<?php
}
mysql_close($con);
?>