title: Can a submit button work without refresh AJAX?
body: <p>I have a problem with my very simple chat. The page is constanly refreshing with AJAX with an timeout of 750ms. If I press or use enter to submit my 'reaction', the page refreshes: is there an way to remove that, so that you can instantly see what you've posted?</p>
  
  <p>You can see the chat at my website: <a href="http://chaotix.nl/chat/" rel="nofollow">chat</a></p>
  
  <p>The code: <br/>
  Index.php</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;?php include 'config.php'; ?&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript" src="jquery-1.7.1.js"&gt;
  function submitenter(myfield,e)
  {
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;
  
  if (keycode == 13)
     {
     myfield.form.submit();
     return false;
     }
  else
     return true;
  }
  
  
  &lt;/script&gt;
  
      &lt;title&gt;JavaScript Chat&lt;/title&gt;
      &lt;link href="style.css" rel="stylesheet" type="text/css"/&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class="container"&gt;
          &lt;div id="chatwindow"&gt;
  
          &lt;/div&gt;
  
          &lt;div class="inputMessage"&gt;
              &lt;form method="post"&gt;
  
  
      enter code here
  
              &lt;hr&gt;&lt;/hr&gt;
                  &lt;textarea name="message" rows="1" cols="55"&gt;&lt;/textarea&gt;&lt;br/&gt;Fill username here&lt;br/&gt;
                  &lt;input type="text" value="" name="username" /&gt;
                  &lt;input type="submit" value="verstuur" name="submit" onKeyPress="return submitenter(this,event)" /&gt;
  
              &lt;/form&gt;
              &lt;?php   include 'send.php'; ?&gt;      
          &lt;/div&gt;
  
          &lt;script type="text/javascript"&gt;
            $(document).ready(function(){
              setInterval ( "get()", 750 );
            });
            function get(){
               $.ajax({
                 type: 'GET',
                 url: 'chat.php',
                 success: function(data){
                   $("#chatwindow").html(data);
                 }
               });
            }
          &lt;/script&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>chat.php</p>
  
  <pre><code>&lt;?php
      include 'config.php';
      $result = mysql_query("select * from Message");
      while($row = mysql_fetch_array($result))
      {
          echo '&lt;p&gt;' . $row['username'] . " : " . $row['message'] . '&lt;/p&gt;';
      }
  ?&gt;  
  </code></pre>
  
  <p>send.php</p>
  
  <pre><code>&lt;?php 
  
  if(isset($_POST['submit'])) 
      {
      if (!empty($_POST['username']))
          {
              if(!empty($_POST['message']))
              {
                  $message =  mysql_real_escape_string(htmlentities($_POST['message']));
                  $username =  mysql_real_escape_string(htmlentities($_POST['username']));
                  $query = "INSERT INTO Message (`username`,`message`) VALUES ('".$username."','".$message."')";
                  mysql_query($query);
              }
              else
              {
              echo '&lt;script type="text/javascript"&gt;alert(\'Je kan niet niks sturen\')&lt;/script&gt;'; 
              }
          }
      else
      {
          echo '&lt;script type="text/javascript"&gt;alert(\'Vul een gebruikresnaam in!\')&lt;/script&gt;';
      }
  }
  ?&gt;
  </code></pre>
  
  <p>if my question is not clear say it please.
  And is there a topic/question/post about good spacing? google translated it as "indent".
  Thanks</p>