title: Use AJAX/JQuery to submit form and show results without reload
body: <p>Im trying to use jquery and ajax to submit a form and show the results without reloading. Like your typical ajax commenting setup.  </p>
  
  <p>My HTML is setup like this:</p>
  
  <pre><code>    &lt;form id="create_new_heading" action="/display.php?brand=1" method="post"&gt;
  
            &lt;label for="entry"&gt;Heading:&lt;/label&gt;&lt;br/&gt;
            &lt;input type="text" id="heading" name="heading" maxlength="150"/&gt;&lt;br/&gt;
  
            &lt;input type="submit" value="Add this Heading" /&gt;
      &lt;/form&gt;
      &lt;div id="result"&gt;
  
     &lt;/div&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>    &lt;script&gt;
        /* attach a submit handler to the form */
        $("#create_new_heading").submit(function(event) {
  
          /* stop form from submitting normally */
          event.preventDefault(); 
  
          /* get some values from elements on the page: */
          var $form = $( this ),
              term = $form.find( 'input[name="heading"]' ).val(),
              url = $form.attr( 'action' );
  
          /* Send the data using post and put the results in a div */
          $.post( url, { s: term },
            function( data ) {
                var content = $( data ).find( '#test_me' );
                $( "#result" ).empty().append( content );
            }
          );
        });
      &lt;/script&gt;
  </code></pre>
  
  <p>Form Processor looks like this:</p>
  
  <pre><code>public function write($p) {
      if ( $_POST['type'] )
        $type = mysql_real_escape_string($_POST['type']);
      if ( $_POST['heading'])
        $heading = mysql_real_escape_string($_POST['heading']);
      if ( $type &amp;&amp; $heading ) {
        $uniqueid = uniqid();
        $sql = "INSERT INTO headings VALUES('$type','$heading','$uniqueid')";
        return mysql_query($sql);
      } else {
        return false;
      }
    }
  </code></pre>
  
  <p>I attempted to follow the jquery documentation for implementing this but I can't seem to get it to work. The form submits, and the entry gets put into the database but I still have to refresh the page to see the new entry. Any idea of what I am doing wrong?</p>