jetroy
10-01-2007, 01:02 AM
I have programmed a supersimple chat with the PHP and HTML all on a single page as shown below:
<?
if(isset($_REQUEST['comment'])) { // if there is a comment
$name=$_REQUEST['name'];
$comment=$_REQUEST['comment'];
$fh=fopen("comments.htm","r");
$c=fread($fh,3333);
fclose($fh);
$fh=fopen("comments.htm","w");
$msg="<h4>$name----$comment</h4>\n";
$c .= $msg;
fwrite($fh,$c);
fclose($fh);
}else { // no comment, set the name to blank
$name="";
}
?>
<html>
<body>
<iframe id="if" src="comments.htm#end" height=233px width=444px scrolling=no frameborder=0></iframe>
<hr>
<form action="chat0.php">
<table>
<tr><td>Name</td><td>Comment</td></tr>
<tr><td><input type = "text" name="name" size=12 value= <? echo $name; ?> > ---- </td> <td><input type = "text" name="comment" size=33></td></tr>
</table>
<input type=submit value="Add comment">
</form>
<input type="button" value="refresh" onClick="document.getElementById('if').contentWindow.location.reload()">
</body>
</html>
---------------
Is it possible to use AJAX and still keep it on a single page?
Thanks
<?
if(isset($_REQUEST['comment'])) { // if there is a comment
$name=$_REQUEST['name'];
$comment=$_REQUEST['comment'];
$fh=fopen("comments.htm","r");
$c=fread($fh,3333);
fclose($fh);
$fh=fopen("comments.htm","w");
$msg="<h4>$name----$comment</h4>\n";
$c .= $msg;
fwrite($fh,$c);
fclose($fh);
}else { // no comment, set the name to blank
$name="";
}
?>
<html>
<body>
<iframe id="if" src="comments.htm#end" height=233px width=444px scrolling=no frameborder=0></iframe>
<hr>
<form action="chat0.php">
<table>
<tr><td>Name</td><td>Comment</td></tr>
<tr><td><input type = "text" name="name" size=12 value= <? echo $name; ?> > ---- </td> <td><input type = "text" name="comment" size=33></td></tr>
</table>
<input type=submit value="Add comment">
</form>
<input type="button" value="refresh" onClick="document.getElementById('if').contentWindow.location.reload()">
</body>
</html>
---------------
Is it possible to use AJAX and still keep it on a single page?
Thanks