title: Trying to submit form on textbox enter press with jquery ajax doesn't work
body: <p>I'm trying to submit a form using jquery and ajax, but it fails. Here's the code:</p>
  
  <pre><code>$(document).ready(function ()
  {
      $('.crazytext').keydown(function (event)
      {
          if (event.keyCode == 13)
          {
              $.ajax(
              {
                  url: '/sendchat.php',
                  type: 'POST',
                  data:
                  {
                      'from': $('#from').val(),
                      'to': $('#to').val(),
                      'when': $('#when').val(),
                      'msg': $('#chatty').val()
                  }
              });
          }
      });
  });
  </code></pre>
  
  <p>It's simple, I want to submit the form once enter is pressed and send data to sendchat.php without reloading the page. This is the html:</p>
  
  <pre><code>&lt;form id="send-message-area" method="POST" action="sendchat.php"&gt;
    &lt;input type="text" name="from" id="from" value="&lt;?php echo $me;?&gt;" hidden&gt;
    &lt;input type="text" name="to" id="to" value="&lt;?php echo $other1;?&gt;" hidden&gt;
    &lt;input type="text" name="when" id="when" value="&lt;?php echo $date;?&gt;" hidden&gt; 
    &lt;textarea class="crazytext" name="msg" id="chatty"&gt;&lt;/textarea&gt;
    &lt;input type="submit" name="chat" values="chat" class="crazytext2" hidden&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And if necessary, the php code for sendchat.php</p>
  
  <pre><code>$fromuser = $_POST['from'];
  $touser = $_POST['to'];
  $when = $_POST['when'];
  $msg = $_POST['msg'];
  $seen = 0;
  $addchat = $db-&gt;prepare("INSERT INTO scorp_chats (Fromuser, Touser, Messagetime, Message, Seen) VALUES (:fromuser, :touser, :messagetime, :message, :seen)");
  $addchat-&gt;execute(array(':fromuser' =&gt; $fromuser, ':touser' =&gt; $touser, ':messagetime' =&gt; $when, ':message' =&gt; $msg, ':seen' =&gt; $seen));
  </code></pre>
  
  <p>That's it really, it's super simple but it fails. If I remove the ajax part completely, it works, but I get redirected to the page, which shouldn't happen. </p>
  
  <p><strong>SOLUTION (Thanks to Barmar):</strong></p>
  
  <pre><code>$(document).ready(function () {
      $('.crazytext').keydown(function (event) { // your input(textarea) class
          if (event.keyCode == 13) {
              event.preventDefault();
              $.ajax({
                  url: 'sendchat.php', // script to process data
                  type: 'POST',
                  data: $("#send-message-area").serialize(), // form ID
                  success: function(result) {
                      $("#result").text(result);
                  }
              });
          }
      });
  });
  </code></pre>