SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

    Code:
    <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

    Code:
    <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

  2. #2
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by william232 View Post
    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

    Code:
    <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

    Code:
    <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

    Code:
    $.post("ChatSend.php", $("#ChatForm").serialize(), function(data)
    What is the problem with that Line??

  3. #3
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,266
    Mentioned
    33 Post(s)
    Tagged
    5 Thread(s)
    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:
    Code JavaScript:
    $("#ChatForm").submit(function(e) {
        e.preventDefault();


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •