title: XMLHttpRequest response 'undefined' ... UNLESS alerting the variable 1st
body: <p>Bugger!</p>
  
  <p>I am using an xmlhttprequest in javascript, calling a php page. The php page is only echoing a string. </p>
  
  <p>When the xmlhttprequest hits 4 200, the response text is saved to a string. Also, the xmlhttprequest is in a function, and that function returns the response text.</p>
  
  <p>THE ISSUE: the function is returning <code>undefined</code>, but I've circumvented the error by adding an <code>alert(string)</code>. The alert then states 'undefined' and the function passes the echoed value on return, AS string!</p>
  
  <p>With Opera, Chrome, Firefox, and Internet Explorer, only FF and IE populate the response text. Opera and Chrome don't work at all.</p>
  
  <p>Code:</p>
  
  <pre><code>    function xmlhttpr(help,type,address)
      {
          var string;
          if ( help )
          {
              string = 'The xmlhttpr function:&lt;br&gt;params: (help,type,address) 
     &lt;br&gt;as&lt;br&gt;false/true,&lt;br&gt;get/post,&lt;br&gt;/addr.ess?h=elp';
             return string;
         }
         if ( !address )
         {
             string = 'Parameter missing in xmlhttpr(0,type,address)';
             return string;
         }
         if ( type == 0 )
         {
             type = 'GET';
          }
         if (type == 1 )
         {
              type = 'POST';
          }
         if ( window.XMLHttpRequest )
         {
              xmlhttp = new XMLHttpRequest();
          }
         else
         {
              xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
        }
         xmlhttp.onreadystatechange = function()
         {
              //alert(this.readyState + ' ' + this.status);
              if ( this.readyState==4 &amp;&amp; this.status==200 )
              {
                  string = this.responseText;
              }
          }
          xmlhttp.open( type , address , true );
          xmlhttp.send();
          alert(string); //STINKY
          if ( string )
          {
              return string;
          }
          else
          {
              return 'Request failure';
          }
      }
  </code></pre>