Scope of Javascript Variable
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5381804/return-from-a-function-ajax">return from a function ajax</a><br>
  <a href="http://stackoverflow.com/questions/7779697/javascript-asynchronous-return-value-assignment-with-jquery">JavaScript asynchronous return value / assignment with jQuery</a>  </p>
</blockquote>



<p>How do you output the data variable to the second alert statement.</p>

<pre><code>        $.post("index.ajax.php", { lookup:value }, 
        function(data) {
            alert(data)
            test = data;
        })
        alert(test)
</code></pre>

<p>Or would it be possible to do something like this?</p>

<pre><code>function confirm_search(input) {
    $.post("index.ajax.php", { lookup:input }, 
    function(data) {
        return data;
    })
}

var test = confirm_search(value);
alert(test); 
</code></pre>
