My function makes two getJSON calls and writes the responses to an array. At the end of the second getJSON call, I used the code snippet below:
alert(files.length);
print_r(files);
console.log(files);
However, the alert shows the correct number of items in the array, but the print_r and console.log functions are not displaying the array items. I need to confirm that I have received the correct items in the array, but the print functionality is not working. Can anyone advise me on how to resolve this issue? (My ultimate goal is to sort the array, remove duplicates, and filter it further.)
<script>
var files = new Array();
function pushtoArray(){
//first getJSON call
var url1 = "https://spreadsheets.google.com/feeds/list/xxxxx/xxxxx/public/values?alt=json";
$.getJSON(url1, function(data) {
var entry = data.feed.entry;
$(entry).each(function(){
// Column names are name, age, etc.
count++;
files.push({ url: this.gsx$url.$t, filename: this.gsx$name.$t });
$('.results').prepend('<h2>'+this.gsx$name.$t+'</h2><p>'+this.gsx$url.$t+'</p>');
});
alert(files.length);
print_r(files);
console.log(files);
});//end of ajax call
//second getJSON call
var url2 = "https://spreadsheets.google.com/feeds/list/xxxxx/xxxxx/public/values?alt=json";
$.getJSON(url2, function(data) {
var entry = data.feed.entry;
$(entry).each(function(){
// Column names are name, age, etc.
count++;
files.push({ url: this.gsx$url.$t, filename: this.gsx$name.$t });
$('.results').prepend('<h2>'+this.gsx$name.$t+'</h2><p>'+this.gsx$url.$t+'</p>');
});
alert(files.length);
print_r(files);
console.log(files);
});//end of ajax call
};//end of function
</script>
HTML code:
<body onload="pushtoArray()">