JavaScript: How to load external text database to webpage at regular interval?

Hello,

I have a webpage (tips.htm) that will show “tips to-day”. There are basically three pages:

  1. tips.html
  2. tip.php
  3. tip_database.txt (has both Chinese and English Characters)

How it works:
The tips that show in tips.html are loaded from tip_database.txt

What I wish?
I wish the tips showing in tips.html refresh every 10 seconds. Therefore my visitors can see a new tip loading from tip_database.txt in every 10 seconds.

How can I do that?

Here’s the contents of the three files. Actually I obtained the Javascript on the Internet long time ago.

MAIN FILE: tips.html

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
http://www.w3.org/TR/html4/loose.dtd”><html>
<head>
<title>Tips Today</title>
<script type=“text/javascript”>
<!–
var index = 0;
var text_list = ;
var file_name = “tip.php?lang=chi”;
function init()
{
if (!xmlHttp)return;
xmlHttp.open(“POST”,file_name,true);
xmlHttp.onreadystatechange=loadFile;
xmlHttp.send(“”);
}
function loadFile()
{
if (xmlHttp.readyState == 4) {
text_list = xmlHttp.responseText.split(
/(?:[\r\s]*
[\r\s]){2,}/g ), len = text_list.length;
index = Math.floor(Math.random() * len);
xmlHttp = null;
showMessage();
}
}
function showMessage()
{
var content = document.getElementById(“content”);
if (!content) {
window.setTimeout(showMessage, 100);
} else {
content.innerHTML = encodeHTML(text_list[index]);
}
}
function encodeHTML(str)
{
return new String(str).replace(/</g, ‘<’).replace(/>/g, ‘>’).replace(/&/g, ‘&’).replace(/
/g, ‘<br />’);
}
//–>
</script>
<script type=“text/javascript”>
<!–
xmlHttp=XMLHttp();
function XMLHttp()
{
try {
if (window.XMLHttpRequest) {
var req = new XMLHttpRequest();
if (req.readyState == null) {
req.readyState = 1;
req.addEventListener(“load”, function () {
req.readyState = 4;
if (typeof req.onreadystatechange == “function”) req.onreadystatechange();
}, false);
}
return req;
} else if (window.ActiveXObject) {
return new ActiveXObject(getControlPrefix()+“.XmlHttp”)
}
} catch ( ex ) {}
}
function getControlPrefix()
{
if (getControlPrefix.prefix) return getControlPrefix.prefix;
var prefixes = [“MSXML2”, “Microsoft”, “MSXML”, “MSXML3”], o, o2;
for (var i = 0; i < prefixes.length; i++) {
try {
o = new ActiveXObject(prefixes
+ “.XmlHttp”);
o2 = new ActiveXObject(prefixes* + “.XmlDom”);
return getControlPrefix.prefix = prefixes*;
} catch (ex) {};
}
throw new Error(“Could not find an installed XML parser”);
}
init();
//–>
</script>

<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>

</head>

<body>
<table width=“760” border=“0” align=“center” cellpadding=“0” cellspacing=“0” class=“td01 style1”>
<tr>
<td valign=“top”>
<div align=“center” class=“content” id=“content” style=“font-style:normal; font-variant:normal; font-weight:normal; font-size:14px; font-family:Arial, Helvetica, sans-serif; width:382; height:59”>
<b>text Appear Here</b>
</div>
</td>

&lt;/tr&gt;	

</table>
</body>
</html>

FILE: tip.php

<?
header(‘Content-Type: text/html; charset=utf-8’);
include(‘tip_database.txt’);
?>

FILE: tip_database.txt

Tips 1: xxxxxxxxxxxxxxxxxxxxxxx

Tips 2: xxxxxxxxxxxxxxxxxxxxxxxx

… More tips here …

Please help.

Thanks and best regards

Alex