I want to make a global variable of the result of the $.getJSON request. If I do it as in my code below I get the a undefined message.
This is my .js code:
      var test = $.getJSON("dropdown_code/get_tables.php", success = function(data)
    {
        var options = "";
    for(var i = 0; i < data.length; i++)
        {
            options += "<option value='" + data[i] + "'>" + data[i] + "</option>";
        }
    $("#slctTable").append(options);
    $("#slctTable").change();
    return data;
}); 
console.log(test);
$("#slctTable").change(function()
{
$.getJSON("dropdown_code/get_fields.php?table=" + $(this).val(), success = function(data)
    {
        var options = "";
    for(var i = 0; i < data.length; i++)
        {
            options += "<option value='" + data[i] + "'>" + data[i] + "</option>";
        }
    $("#slctField").html("");
    $("#slctField").append(options);
    $("#slctField").change();
    return data;
});    
});
}); 
 
    