title: HTML / AJAX / PHP synchronous harmony? Could asynchronous ever work?
body: <p>I've been working out the best way to bridge javascript to get data from php with Ajax.
  And all while trying to keep the lines of code to a minimum and with greatest speed.
  I've come up with a way to pass AJAX a value by Object so it can be altered as if it was passed by reference and then send it back. But so far, I can only do this synchronous as the data will not be available until AJAX completes. </p>
  
  <p>Point is:
  I've been looking for an easy way access all of my PHP content with javascript.
  Build a simple javascript(GetSomePHPstuff) API  if you will.</p>
  
  <p>As I am a novice at web programming, I would love to hear some input and feedback on this.
  This is what I have come up with.</p>
  
  <p><strong>In this example, I am sending a text value from html through javascript to ajax to php and php sends it back to ajax back to javascript back to my html page.</strong></p>
  
  <p>Here is our simple HTML type file.</p>
  
  <p><strong>TEST.html</strong></p>
  
  <pre><code>&lt;script language="javascript" src="ajax.js"&gt;&lt;/script&gt;
  
  &lt;input type="text" id="text"/&gt;
  &lt;input type="button" value="Return Text" 
  onClick="alert(ajaxReturnText(document.getElementById('text').value));"/&gt;
  </code></pre>
  
  <p>Here is the ajax/javascript file.</p>
  
  <p><strong>AJAX.js</strong></p>
  
  <pre><code>function ReturnText(input, output){
      if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
      else{// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function(){
          if(xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200){
              output.value = xmlhttp.responseText;
          }
      }
  
      xmlhttp.open("GET","php.php?text="+input,false);
      xmlhttp.send();
  }
  
  function ajaxReturnText(input){
      var output = new Object();
      ReturnText(input, output);
      return output.value
  }
  </code></pre>
  
  <p>And here is the PHP file</p>
  
  <p><strong>php.php</strong></p>
  
  <pre><code>&lt;?php 
  function ReturnText($text){
      return $text;
  }
  if($text = $_GET["text"]){
      echo ReturnText($text);
      die();
  }
  ?&gt; 
  </code></pre>