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
}