title: Calling specific php functions using Ajax with vanilla JS
body: <p>So I have done a bit of reading over the last few days as I attempt to learn about Ajax. </p>
  
  <p>Most advice online seems to use jQuery, so I think this question will help anyone who wants to use vanilla JS instead. </p>
  
  <p>Suppose I have a PHP file that queries the database that looks like this:</p>
  
  <pre><code>function1($parameter1){
  // some code to query database
  }
  
  function2($parameter2){
  // some code to query database
  }
  
  function3($parameter3){
  // some code to query database
  }
  
  </code></pre>
  
  <p>I want to make an Ajax call that targets a specific function for two reasons: </p>
  
  <ul>
  <li>other functions are irrelevant for this call</li>
  <li>or otherwise, I am not sure if you can get the result of more than one function from a single Ajax call? </li>
  </ul>
  
  <p>So as far as reading tells me, to call specific functions, I need to add parameters in my XML requests, for example, $q$, $r$, $s$ and wrap each of my function in an if loop as follows: </p>
  
  <pre><code>
  if($q === 1){
    function1($parameter1){
    // some code to query database
    }
  }
  
  if($r ===1){
    function2($parameter2){
    // some code to query database
    }
  }
  
  if($s ===1){
    function3($parameter3){
    // some code to query database
    }
  }
  
  </code></pre>
  
  <p>Then I can use something like <code>xmlhttp.open("GET","file.php?q=1",true)</code> to target function 1 etc.</p>
  
  <p>Is this the way to go or is there something more efficient? Efficiency in that it <em>seems</em> inefficient to have to wrap each function in an if loop to call it and something makes me think that this would have been thought of and another solution implemented.</p>