title: How to post a form to PHP using Ajax .serialize() data?
body: <p>I am using WordPress and cannot figure what to do with the serialized data from Ajax after it is sent over.  I have read on this site that <code>parse_str</code> is what I need, but I am unsure how to make use of it.  </p>
  
  <p>Here is the jQuery for the Form Submit</p>
  
  <pre><code>jQuery( document ).ready( function( $ ) { 
      $( '#log_data' ).submit( function( event ) { 
          event.preventDefault(); 
          console.log( $( this ).serialize() );
  
          var data = $(this).serialize();
          action = 'my_submit_log_action';
          $.post( 
              ajaxurl, 
              data,
              function ( response ) { 
                  if ( ! response.success ) { 
                      alert( 'Failure!' ); 
                  } 
                  alert( 'Success!' );                          
              } 
          ); 
      }); 
  });
  </code></pre>
  
  <p>Because this is in WordPress, I have to pass an action so WordPress knows what function to pass this data to.  I am not sure if I am passing the action right (see above).  </p>
  
  <p>The second part is the PHP, which is what I do not understand.  How do I take the serialized data and post it to the database?</p>
  
  <pre><code>add_action('wp_ajax_my_submit_log_action', 'my_submit_log_action');
  add_action('wp_ajax_nopriv_my_submit_log_action', 'my_submit_log_action');
  function my_submit_log_action() {
      global $wpdb;
  
      $user_id = $_POST['user_id'];
      $length = $_POST['length'];
      $ground = $_POST['ground'];
      $date = $_POST['date'];
      $notes = $_POST['notes'];
  
      $wpdb-&gt;insert('wp_jo_plugin_options', array (
          'user_id' =&gt; $user_id,
          'length'  =&gt; $length,
          'ground'  =&gt; $ground,
          'date'    =&gt; $date,
          'notes'    =&gt; $notes,
      ) );
  
      die();
  }
  </code></pre>