title: Using AJAX to process SQL from within WordPress
body: <p>I am in the process of trying to learn AJAX. For now, I want to read and write MySQL tables from within WordPress. There are lots of tutorials out there, but so far I haven't managed to get any of them to work. I'm sure it's because this is all new and I'm simply not understanding something basic about the process.
  If I can get a very simple call to work, I'm sure I can expand on that and figure out what I need from there.
  Here is what I'm working on currently. </p>
  
  <p>Functions.php</p>
  
  <pre><code>add_action( 'wp_ajax_wps_get_time', 'wps_get_time' );
  add_action( 'wp_ajax_nopriv_wps_get_time', 'wps_get_time' );
  function wps_get_time() {
      $format = $_POST['format'];
      echo date( $format );
      die();
  }
  
  function sonata_script_includer() {
      wp_register_script( 'ajax-test', get_template_directory_uri() . '/js/ajax-test.js', array( 'jquery' ), false, true);
      wp_enqueue_script(' ajax-test' );
  }
  add_action( 'wp_enqueue_scripts', 'sonata_script_includer' );
  </code></pre>
  
  <p>Javascript is in: (theme directory) '/js/ajax-test.js'</p>
  
  <pre><code>var format = 'U';
  jQuery.ajax({
      type: "POST",
      url: "admin-ajax.php",
      data: { action: 'wps_get_time', format: format }
  }).done(function( response ) {
      alert( response );
  });
  </code></pre>
  
  <p>HTML is just a simple onclick event.</p>
  
  <pre><code>&lt;button ... onclick="ajax-test()"&gt;
  </code></pre>
  
  <p>Edit: After posting this, I realized that my current code has nothing to do with SQL as stated in my Title. My goal is to process SQL queries, but currently I'm just trying to get a simple AJAX call to work. I'll add the SQL once I get something to work.</p>