I have this simple code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>testing</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
<!--
var xmlhttp = false;
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch (E){
xmlhttp = false;
}
}
if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
xmlhttp = new XMLHttpRequest();
}
function makerequest(serverPage, objID){
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
obj.innerHTML = xmlhttp.responseText;
setTimeout(makerequest(serverPage,objID),1000);
}
}
xmlhttp.send(null);
}
window.onload=function(){
setTimeout(makerequest('inner.php','first'),1000);
}
//-->
</script>
</head>
<body >
<div align="center">
<h1>Testing</h1>
</div>
<div id="first">loading...</div>
<div id="second">...and loading...</div>
</body>
</html>
I'm just testing an "auto-refresh" function that I need to use. The page that I call (inner.php) just displays the current time (for now). It seems to be working alright in Firefox, but not in IE. Also, in Firefox I get an error:
useless setTimeout call(missing quotes around argument?) and I don't know how to fix it. Any ideas?
Also, I tried calling the same setTimeout function sending it the id for the second div, but it doesn't do anything. How could I have different divs auto-refreshing at different rates?
Any help will be really appreciated!