title: Calling PHP function from AJAX?
body: <p>I'm using a lot of AJAX calls where I'll say,</p>
  
  <pre><code>data: {action: "get_categories", etc..}
  </code></pre>
  
  <p>and then in my PHP I'll say,</p>
  
  <pre><code>if(isset($_POST['action']) &amp;&amp; ($_POST['action'] == 'get_categories')) { 
  //do stuff
  }
  </code></pre>
  
  <p>I'm trying to refactor the code a bit, and I'd like to take the output of one of these code blocks and pass it into another one, but its not a PHP function, so I'm not really sure how to do that?  Is there a way to call a PHP function directly from the AJAX call, rather than using action?</p>
  
  <p>Also, in using this style of PHP code block I have to call the code below in every single code block, and I'm not sure why?  I thought if I put it at the top of my php file, and used require_once that might work but nothing I try works unless I include these in every single code block.</p>
  
  <pre><code>require("config.php");
  require("database.php");
  </code></pre>