Here is one example quickly thrown together:
Code:
<html>
<head>
<script type="text/javascript">
// NOTE: This example uses POST to avoid problems with IE caching GET
// One problem that POST has is it doesn't handle reloading HTML files well. If your file is php or asp no problem
var refreshInterval; // variable to store the interval object
var refreshTime = 60000; // refresh every 60000ms or 1 minute
var refreshURL = "mypage.asp"; // asp page to load into div
function HTTPReq() {
var theAJAX;
if(window.XMLHttpRequest) {
theAJAX = new XMLHttpRequest();
if(theAJAX.overrideMimeType) {
theAJAX.overrideMimeType('text/xml');
}
} else if(window.ActiveXObject) {
try {
theAJAX = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e){
try {
theAJAX = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
theAJAX = false;
}
}
}
if(!theAJAX){
alert('Giving up :( Cannot create an XMLHTTP instance');
}
return theAJAX;
}
function doAjaxPost(paramList,url,onsuccess,onfail) {
var ajax = HTTPReq();
if (!ajax) return;
var paramArr = [];
for (var item in paramList) {
// don't handle arrays, objects, functions, etc
if (typeof paramList[item] == "string" || typeof paramList[item] == "number") {
paramArr.push(encodeURIComponent(item) + "=" + encodeURIComponent(paramList[item]));
}
}
var params = paramArr.join("&");
ajax.open("POST", url, true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
ajax.onreadystatechange = function() {
if (ajax.readyState == 4) {
if (ajax.status == 200 || ajax.status == 0) {
onsuccess(ajax.responseText);
} else {
onfail(ajax.status);
}
}
}
ajax.send(params);
}
function loadPage() {
doAjaxPost({},refreshURL,
function (ajaxText) {
document.getElementById("refreshMe").innerHTML = ajaxText;
},
function (statusCode) {
alert("error loading page, status was " + statusCode);
}
);
}
window.onload = function() {
refreshInterval = window.setInterval(loadPage,refreshTime);
}
</script>
</head>
<body>
<div id="refreshMe">some content I want to refresh</div>
</body>
</html>
Bookmarks