the js
Code:
      function Chat() {
         $.ajax({
            type: "POST", url: "/chat/chat.php",
            data: $("#message").serialize(),
            success: function(response){
				if meny.isOpen();
					{
					meny.Open();
					}
               $("#message").val("");
               $("#chat_box").load("#chat_box");
               $("#chat_box").scrollTop($("#chat_box")[0].scrollHeight);
            }
         });
         return false;
      }
      setTimeout(function () {
         $("#chat_box").load("#chat_box");
      }, 200);
      setTimeout(function() {
         $("#chat_box").scrollTop($("#chat_box")[0].scrollHeight);
      }, 1000);
      setInterval(function () {
         $("#chat_box").load("#chat_box");
         $("#chat_box").scrollTop($("#chat_box")[0].scrollHeight);
      }, 2000);
    </script>
the php/html
Code:
<div class="chat">
	<div id="chat_box">
	<!--ajax will put chatlog here-->
	</div>
	<?php
		if (isUserLoggedIn()){ 
		echo '<form id="chat_message" onsubmit="Chat();">';
		echo '<input type="text" id="message"></input>';
		echo '<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;" value="POST"/>';
		echo '</form>';

		} else {
		echo '<div id="LoggedOut"><b>You must be logged in to chat</b></div>'; 
		}
		
	?>	
	</div>
the ajax/php
Code:
error_reporting(0);

//  A chatroom that uses the jquery version below:
//  http://hostpile.info/jquery-1.9.1.js
include("../models/config.php")
// original script by zelles
// modified by r3wt


$uid = $loggedInUser->user_id;
$username = $loggedInUser->display_username;
$ajax='';
if($ajax==='chat_message') {
	$message = addslashes(strip_tags($_POST['message']));
	mysql_query("INSERT INTO chat_messages (id,username,message, User_ID) VALUES ('','$username','$message','$uid')");
	die();
	}
if($ajax==='chat_box') {
	$Query = mysql_query("SELECT Username, message FROM chat_messages ORDER BY id DESC LIMIT 30");
	while($Row = mysql_fetch_assoc($Query)) {
	$chat_username = $Row['Username'];
	$chat_message_text = $Row['message'];
	$chat_message_text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\\"\\\\0\\" target='_blank'>\\\\0</a>", $db_chat_message);
	$newcomment = '<p style="font-size: 12px; padding-bottom: 3px;"><b>'.$chat_username.': </b>'.$chat_message_text.'</p>';
	$chat_line = $newcomment;
	die();
	}