title: Calling PHP function from JQuery/Ajax
body: <p>It's clear from reading through threads that I can call a PHP function using Ajax / JQuery, but I can't quite get my head around the particulars. </p>
  
  <p>Let's say I have a function foo() which simply adds 'bar' to some string I pass in. foo() lives in foo.php. To use this in my JavaScript-less HTML, I'd do something like this:</p>
  
  <pre><code>&lt;?php include 'foo.php';?&gt;
  &lt;?php echo foo('bar')?&gt;
  </code></pre>
  
  <p>...and my output is "foobar". Great.</p>
  
  <p>I suspect I do something like so to grab the output of foo() via JavaScript:</p>
  
  <pre><code>&lt;script&gt;
  $.post("http://foo.com/foo.php", {
  
    &lt;Magic happens here&gt; 
  
  }, function(response) {
  useTheOutput(response);
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>....but I'm not clear on whether I should be POSTing or GETing...and how to pass in a value, like 'bar'.</p>
  
  <p>Can anyone push me in the right direction? Here are other threads that discuss the same thing, I just can't connect all the dots:</p>
  
  <p><a href="https://stackoverflow.com/questions/7165395/call-php-function-from-javascript">Call php function from javascript</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3130629/call-function-in-jquery-ajax">call function in jquery-ajax</a></p>