title: Calling a specific function from PHP with Jquery & Ajax
body: <p>For me this is something new, so I am just researching this and trying to understand it.
  As you can see in the php script there are 2 functions and I am trying to call a specific one with jquery.</p>
  
  <p>Now if I have one function then I can do it, but when I have 2 or more I am starting to get stuck.
  I suppose I could do this when I have 2 functions, but as soon as more variables are in play or more functions do I just make massive if statements in my php?</p>
  
  <p>The problem is that when I attach a database to it, I would need to consider all inputs that can happen.
  <strong>How do I specify a specific php function when using jquery &amp; ajax?</strong></p>
  
  <pre><code>//function.php
  &lt;?php
      function firstFunction($name)
      {
          echo "Hello - this is the first function";
      }
  
      function secondFunction($name)
      {
          echo "Now I am calling the second function";
      }
  
  ?&gt;
  
  &lt;?php
      $var = $_POST['name'];
  
      if(isset($var))
      {       
          $getData = firstFunction($var);
      }
      else if(isset($var))
      {
          $getData = secondFunction($var);
      }
      else
      {
          echo "No Result";
      }
  
  ?&gt;
  
  //index.html
  &lt;div id="calling"&gt;This text is going to change&gt;&lt;/div&gt;
  
  &lt;script&gt;
  
       $(document).ready(function() {
          $('#calling').load(function() {
          $.ajax({
              cache: false,
              type: "POST",
              url: "function.php",
              data: 'name=myname'
              success: function(msg)
              {
                  $('#calling').html((msg));
              }
  
              }); // Ajax Call
          }); //event handler
      }); //document.ready
  
  &lt;/script&gt;
  </code></pre>