title: In AJAX how to retrive variable from inside of onreadystatechange = function ()
body: <p>Is it possible to retrieve variable set in <code>onreadystatechange</code> function from outside the function?
  <bR>--edit--<BR>
  Regarding execution of functions:<BR>
  If its possible i would like to execute ajaxFunction()  with one click<BR>
   and then popup() with next click, or 
  somehow wait for ajax function to end and then call for alert box<BR></p>
  
  <p><BR>In pseudocode:</p>
  
  <pre><code>function ajaxFunction(){
      //creating AJAX 
      ...
      // Create a function that will receive data sent from the server
      ajaxRequest.onreadystatechange = function (){
          if(ajaxRequest.readyState == 4){
              //success code
              ======&gt;Here i want to set variable &lt;=====
              var MyVariable='MyContent';
          }
      }
      //Retrieving page
      ....
  }
  
  function popup(){
      ajaxFunction();
      alert(MyVariable);
  }
  </code></pre>