Getting value from Ajax request in variable
<p>I've this function.</p>

<pre><code>function ajaxtakesource4(callback){
    var ajaxRequest;  // The variable that makes Ajax possible!
    try{
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                alert("Your browser broke!");
                return false;
            }
        }
    }   
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange =function(){
        if(ajaxRequest.readyState == 4 &amp;&amp;ajaxRequest.status==200){
            var sourcetest = ajaxRequest.responseText;  
            callback(sourcetest);
        }
    }
    ajaxRequest.open("POST", "takesource4.php", true);
    ajaxRequest.send(null); 
}
</code></pre>

<p>Also:</p>

<pre><code>var somous4;
function run() {
    ajaxtakesource4(function(sourcetest){   
        somous4=sourcetest;
    });
    alert(somous4);
}
</code></pre>

<p>and here I call the above the function:</p>

<pre><code>&lt;div id="run"&gt;
  &lt;button id="button_run" class="button" onclick="run()"&gt;Run&lt;/button&gt;
&lt;/div&gt;
</code></pre>

<p>When I click on the button it's supposed to alert response from Ajax request, but looks to be alerting a falsy value (<code>undefined</code>), as seen in this line:</p>

<pre><code>alert(somous4);
</code></pre>