...

AJAX all on one page

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

BarrMan
10-03-2007, 04:15 PM
You mean without having to create another server-side page to recruit to the AJAX function?
Yes, you can that but you'll need to have your page written in somekind of server-side language.
You can do that by add in the query when you try to recruit the page something like that: ?AJAX_Page=true.
Then you check: if($_GET["AJAX_Page"] == true) and then if it is true you show the page you want to view for the AJAX function.

Sorry if the PHP function isn't right.. I'm an ASP/.NET programmer.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum