JQuery PHP Chatroom

Hi all,

I am working on a PHP Chat Script with multi-room support that also runs off a database anyway im trying to intergrate JQuery to make it more instant anyway

This is my Jquery script


<script type="text/javascript" src="JQuery.js"></script>
	<script type="text/javascript">
	$(document).ready(function()
	{
		$("#Loadin").load('room.php');
		$("#ChatForm").submit(function()
		{
			//
			$.post('ChatSend.php', $('#ChatForm').serialize(),function(data)
			{
				alert(data);
			});
			//
		});	
	});
    </script>

And this is my html coding


<div id="cwall">
                  <div id="screen">
                      <div id="Loadin"></div>
                  </div>
                   <div id="room">
                          <div id="innerwall"></div>
                    </div>
                  <div id="chat">
                  <table>
                      <form method="post" id="ChatForm" action="">
                      	<?
						?>
                        	<input type="hidden" name="user" value="<? echo $user;?>" />
                            <input type="hidden" name="rank" value="<? echo $rank;?>" />
                            <input type="hidden" name="rid" value="<? echo $rid;?>" />
                          <tr>
                              <th>Message:</th>
                              <th><input type="text" name="message" /></th>
                              <th><input type="submit" value="Send" /></th>
                             <th></th>
                          </tr></form>
                      </table>
                  </div>
              </div>

So my Question is Why isnt the alert poping up any error or showing anything at all so i can see what is going on here if there was an error my alert box would alert me there is an error?

So why is it not showing anything at all?

Thanks,William

I Have located the problem this is the line


$.post("ChatSend.php", $("#ChatForm").serialize(), function(data)

What is the problem with that Line??

Hi William,

The problem is actually on your submit handler. You need to prevent the form’s default action (to submit itself), otherwise your ajax request will never be fired.
You just need to modify your code slightly, to look like this:

$("#ChatForm").submit(function(e) {
    e.preventDefault();