plik który odczytuje i wyświetla treść(chat.php):
Kod
<?
if($_POST["text"])fwrite(fopen("chat.txt", "a"), $_POST["text"])
readfile("chat.txt");
?>
a plik główny:
Kod
<html>
<head>
<script>function ZapytaniePHP(url, idek, dod){
if(dod==undefined)dod=null;
if (window.XMLHttpRequest)xmlHttp = new XMLHttpRequest();
else if (window.ActiveXObject)xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
if (xmlHttp == null){alert("Nie udało się zainicjować obiektu xmlHttpRequest!");return;}
xmlHttp.onreadystatechange = function (){
if (xmlHttp.readyState == 4 || xmlHttp.status == 200){
document.getElementById(idek).innerHTML = xmlHttp.responseText;
}
}
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.send(dod);
}
function czytaj(){
ZapytaniePHP('chat.php', 'identy');
setTimeout("czytaj()", 1000);
}
</script>
</head>
<body onLoad='czytaj()'>
<div id=identy></div>
<input id=text><input type=button value=zapisz onclick="ZapytaniePHP('chat.php', 'identy'. document.getElementById('text').value)">
</body>
</tml>
troche pisane z głowy więc mogą być błędy, ale myśle ze się połapiesz;)