title: How to get PHP to return JSON for inline form submission?
body: <p>tried searching this many times over but I must be missing something simple.</p>
  
  <p>Simply put, I'm trying to submit my form over AJAX to a PHP script that returns JSON. I then perform actions client-side, based on the result of the submission (e.g. displaying errors). However, all I'm getting is my PHP script output - it's not being returned to my AJAX request.</p>
  
  <p>Here is my form:</p>
  
  <pre><code>&lt;form id="storyform" name="storyform" method="post" action="submitform.php" class="story-form" enctype="multipart/form-data"&gt;
  
      &lt;fieldset name="summary"&gt;
          &lt;legend&gt;Your Story &lt;span class="required"&gt;(required)&lt;/span&gt;&lt;/legend&gt;
  
          &lt;p&gt;&lt;label for="title"&gt;What is your story about?&lt;/label&gt;
          &lt;input type="text" id="title" value="" tabindex="" name="title" /&gt;&lt;/p&gt;
  
          &lt;p&gt;&lt;label for="description"&gt;What happened?&lt;/label&gt;
          &lt;textarea id="description" tabindex="" name="description" cols="80" rows="10"&gt;&lt;/textarea&gt;&lt;/p&gt;
      &lt;/fieldset&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is the jQuery that handles the AJAX submission:</p>
  
  <pre><code>  jQuery("#storyform").submit(function(event) {
  
      /* stop form from submitting normally */
      event.preventDefault(); 
  
      /* get some values from elements on the page: */
      var $form = $( this ),
          url = $form.attr( 'action' ),
          postData = {
              "title" = $form.find( '#title' ).val(),
              "description" = $form.find('#description').val()
          };
  
      /* Send the data using post and put the results in a div */
      jQuery.ajax({
          type: "POST",
          url: url,
          data: postData,
          success: function(response){
              jQuery('#result').empty().append(response);
          }
      });
    });
  </code></pre>
  
  <p>I have a div with an ID of "result" after my form...</p>
  
  <p>Then, submitform.php has;</p>
  
  <pre><code>if (!empty($_POST['title'])) {
      $new_post['post_title'] =  sanitize($_POST['title'], '');
  } else {
      $errors['title'] = 'empty';
  }
  
  // Sanitise and prep the description
  if (!empty($_POST['description'])){
      $new_post['post_content'] = sanitize($_POST['description']);
  } else {
      $errors['description'] = 'empty';
  }
  echo json_encode($errors);
  </code></pre>
  
  <p>When submitting the form I expect to see my #results div populated with the JSON from submitform.php. Instead, I just get taken to submitform.php, away from my form, and all I see is that echoed JSON.</p>
  
  <p>How do I get the JSON returned so that I can perform actions based on the content of it?</p>