title: AJAX request using admin-ajax.php
body: <p>I'm trying to do an AJAX request in an WordPress plugin. The request is initiated on the front page embedded in an article using a custom shortcode.</p>
  
  <p>I tried to combine infos from <a href="http://codex.wordpress.org/AJAX_in_Plugins" rel="nofollow">the documentation</a> and <a href="http://www.wopsta.de/using-an-ext-js-datagrid-with-ajax-in-the-wordpress-administration-panel/" rel="nofollow">this tutorial</a>.</p>
  
  <p>However something is going wrong when testing that method... the AJAX query hook isn't called.</p>
  
  <p>This is how my <code>page.php</code> script is called for short code delivery:</p>
  
  <pre><code>add_shortcode('testshortcode', 'TestShortCodeFunction');
  
  function TestShortCodeFunction($attributes)
  {
     ob_start();
     include(__DIR__.'/page.php');
     return ob_get_clean();
  }
  </code></pre>
  
  <p>This is my compacted test script <code>page.php</code>:</p>
  
  <pre><code>&lt;?php
  
      add_action('wp_ajax_test', 'Test');
      add_action('wp_ajax_nopriv_test', 'Test');
  
      // do_action('wp_ajax_nopriv_test'); this calls Test()
  
      function Test()
      {
          echo 'Hallo';
          die();
      }
  ?&gt;
  
  &lt;script type='text/javascript'&gt;
  
      jQuery(document).ready(function() {
  
          console.log("JS query started");
  
          // The following does not call test()
          jQuery.ajax({
              type: "POST",
              url: "http://127.0.0.1/wordpress/wp-admin/admin-ajax.php?action=test",
              success: function(data) {
                  console.log("Query returned: "+data);
              }
          });
  
      });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Output on the console is:</p>
  
  <pre><code>JS query started
  Query returned: 0 
  </code></pre>
  
  <p>The <code>Test()</code> function is never call according to the PHP debugger.</p>
  
  <p>The <code>admin-ajax.php</code> is executed according to the network monitor (<code>URL http://127.0.0.1/wordpress/wp-admin/admin-ajax.php?action=test</code>) but returns <code>0</code>.</p>
  
  <p>Inside <code>admin-ajax.php</code> <code>do_action('wp_ajax_test')</code> is called according to the PHP debugger.</p>