Hi everyone i am new to javascripting and ajax.
I was wonding if you guys can help me with something.
Basically ive got a socialengine script like facebook.
In the feed which posts what everyone is doing i would like that div which is called
HTML Code:
<div id ="userhomerefresher"></div>
How do i make it so that div refreshes every 5 seconds.
I have tried to do it like this
HTML Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test code</title>
<script type="text/javascript" src="js/autorefresher.js"></script>
</head>
<body>
<div id="userhomerefresher"></div>
</body>
</html>
And i have a js file which is coded like this:
HTML Code:
// JavaScript Document
function loadXMLDoc(url)
{
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
xmlhttp.open("GET",url,true)
xmlhttp.send(null)
xmlhttp.onreadystatechange=state_Change
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
if (xmlhttp)
{
xmlhttp.open("GET",url,true)
xmlhttp.send()
xmlhttp.onreadystatechange=state_Change
}
}
}
function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
{
// if "OK"
if (xmlhttp.status==200)
{
document.getElementById('userhomerefresher').innerHTML=xmlhttp.responseText;
}
}
}
function init() {
window.setTimeout( "loadXMLDoc( \"other_doc.html\" );", 5000 );
// OR
// window.setTimeout( "loadXMLDoc( \"page.php?req=true\" );", 5000 );
}
This unfortunatly doesnt work.
Can someone help me and please bare in mind i am very very new to javascripting.
Thanks
Robert
|