Variable ends up undefined after using $.get
<p>This seems like an incredibly simple issue but I have no idea why I'm getting undefined. I'm using jQuery to fetch data off a PHP script - specifically a string which the PHP file echoes. Here's the code:</p>

<pre><code>&lt;script type="text/javascript"&gt;

    var map1;

    $.get("script.php", function(data)
    {
        map1 = data;
    });

    alert(map1);

&lt;/script&gt;
</code></pre>

<p>Now if I alert(map1), it ends up being undefined... why exactly is this the case? I thought by declaring map1 outside $.get, it would fix the problem but that's not the case. If I alert(map1) inside the $.get function, it ends up fine and the variable holds a string (as opposed to being undefined). So the question is... what's going on with map1? And how can I stop it from being undefined / going out of scope / whatever is happening to it?</p>

<p>Thanks in advance.</p>
