Is it possible to re-use an array taken from PHP via JSON in a $.ajax function?



PHP Snippet 1:

$(document).ready(function() {
    var jsonData; // this is the variable where we will store the data
    $('#indicators').change(function() {
        $('#country1').fadeIn('slow');
        var indic_val = $(this).val();
        $.ajax({
            url: 'scripts/chart_handler.php',
            dataType: "json",
            type: 'post',
            data: {'indicator' : indic_val},
            async:false,
            success: (function ( data ){
                jsonData = data; //that's all what you need
                $.each(data, function(i, key) {
                    $('#country1').append('<option value="'+ key +'">'+ key +'</option>');
                });
            }),
        });
    });
});

PHP Snippet 2:

success: (function ( data ){
         myFunction(data);
        $.each(data, function(i, key) {
            $('#country1').append('<option value="'+ key +'">'+ key +'</option>');
        });
    }),

function myFunction(data){
  // do your stuff
}