Async - you're doing it wrong

example code for http://stackoverflow.com/questions/9266841/variables-inside-functions-inside-functions-in-javascript

by bjelline

HTML

<input id="start" value="start" type="button">
<ol id="output"><li>was passiert wann?</li></ol>

CSS

#output{ background-color: #ddd }

JavaScript

function out(s) {
    $('#output').append('<li>' + s + '</li>');
}

function grabdata() {
    var json;
    out('launching first call');
    $.get('/', function(data) {
        json += "in 1\n";
        out('data from first call');
        out('launching second call');
        $.get('/', function(data2) {
            json += "in 2\n";
            out('data from second call');
        });
        out('call 2 has been sent');
    });
    out('call 1 has been sent');
    out('json at the end of grabdata:' + json);

}



$('#start').click(grabdata);