Accessing variable from callback using AJAX in jQuery
<p>Code explains all:</p>

<pre><code>//
// … code ...
//
$.ajax({
    dataType: "json",
    url: "foo",
    success: function(data) {
        var my_data = data;
    }
});
//
// … code ...
//
console.log(my_data); // NOT in scope
</code></pre>

<p>How do I get access to <code>my_data</code> outside of the AJAX call?  I've read that maybe a closure is needed?  I can't find any examples that do want I want though.</p>

<p>Many thanks.</p>
