Código HTML:
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Jackson666" />
<title>Untitled 2</title>
</head>
<body onload="setTimeout('startAjax()',5000)">
<div id="myDIV" style="width: 150px; height: 150px; border: 1px solid #000;"></div>
<script type="text/javascript">
var xmlHttp = false;
function startAjax(){
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}else{
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}catch (e){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
alert("No AJAX!?");
return false;
}
}
}
if(xmlHttp !== false){
xmlHttp.open("GET","archivo.php");
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var resp = eval("(("+xmlHttp.responseText+"))");
document.getElementById('myDIV').innerHTML = '';
for(var i in resp){
document.getElementById('myDIV').innerHTML += resp[i];
}
}
}
}
xmlHttp.send(null);
}
}
</script>
</body>
</html>
Y tu "archivo.php"
Código PHP:
<?php
$array = file('algo.txt');
echo json_encode($array);
?>