jQuery ajax post success - saving data to variable
<p>I have this function:</p>

<pre><code>function getReport(name,x) {
    var xArr = [];
    var yArr = [];
    $.ajax({
        async: false,
        type: "POST",
        //async: false,
        //dataType: "json",
        url: "reportAjax.php",
        data: "name="+ name,
        success: function(data){
            var json = $.parseJSON(data);
            var chartDesc = json.INFO.DESC;
            $.each(json.RESULT, function(i, object) {
                $.each(object, function(property, value) {
                    //alert(property + "=" + value);
                    if (property == x) {
                        xArr.push(value);
                    }
                    else {
                        yArr.push(parseInt(value));
                    }

                });
            });                
        }
    }); 
    console.log(xArr);
    console.log(yArr);
    console.log(chartDesc);
    drawChart(xArr,yArr,chartDesc);
}
</code></pre>

<p>For some reason, I can see in the <code>console.log</code> the values of <code>xArr</code> and <code>yArr</code>, but I get <code>chartDesc is not defined</code> for <code>chartDesc</code>.</p>

<p>If I move the <code>console.log(chartDesc)</code> line to be under this line <code>var chartDesc = json.INFO.DESC</code> I can see it properly.</p>

<p>Why is that?</p>
