title: How to read true/false response from server-side script to return true/false to a jQuery function?
body: <p>I have a jQuery process that I want to run, but only if a response from a PHP script is <code>true</code>.</p>
  
  <p>I want to check the output of a few different PHP scripts every 2 seconds, which will determine whether my jQuery process can proceed.</p>
  
  <p>How can that be done?</p>
  
  <p>I get stuck when needing to use the <a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow">ajax()</a> function as the resulting data from PHP would be passed to a <code>success</code> callback function. I can't figure out how to get my <code>check_php_script_A_returns_false()</code> function to return <code>true</code> or <code>false</code>.</p>
  
  <p>Here's what I have in mind:</p>
  
  <pre><code>$(document).ready(function()
  {
      $('#switch').prop('checked', false);
  
      // Listen event: turn process off/on
      // Every 2 seconds, call is_trigger_met() to see if process can be kicked off.
      var intervalId = null;
      $('#switch').change(function(){
        if ($(this).is(':checked'))
          intervalId = setInterval(is_trigger_met, 2000);
        else
          clearInterval(intervalId);
      });
  }
  
  
  function is_trigger_met() {
      if ( check_php_script_A_returns_false() )
          return false;
  
      if ( check_php_script_B_returns_false() )
          return false;
  
      // ... run my process here ...
  
      return true;
  } 
  
  function check_php_script_A_returns_false() {
      // What do I do here to check php script?
      // Do I use jQuery.ajax() function with async = false? 
      // If so, an the PHP response is TRUE, how do I make that 
      // 'return true/false' for THIS check_php_script_A_returns_false() function?
      return true/false;
  }
  </code></pre>