I need to retrieve an array from a PHP file which is a SQL query coming back in an array.
I've encoded it in with json_encode();
and returned it.
Here is my JS file:
$(document).ready(function() {
$('#indicators').change(function() {
$('#countries').fadeIn('slow');
var indic_val = $(this).val();
var countries = $.ajax({
url: 'scripts/chart_handler.php',
dataType: "json",
type: 'POST',
data: {'indicator' : indic_val},
async:false,
success: (function ( data ){
console.log(data);
$.each(data, function(i,key) {
$('#countries').append('<option value="'+ key +'">'+ key +'</option>');
});
})
});
});
});
I am getting inside success tag but data is coming back null. What do I have to use to get the data array?