0

i'm creating loop using for each to call multiple API,but return undefined when display on console and html. Please help because i cant see my mistake.

var i, len;
var a = ["1", "2", "3", "4"];
var api_scan = [];
var total_scan = [];
var jsonData;
for (i = 0; i < a.length; i++) {

    api_scan[i] = '/api/v1/file/?folder_id='+a[i];
    console.log(api_scan[i]);

    function updateData() {


        jsonData = $.ajax({
            url: api_scan[i],
            dataType: 'json',
        }).done(function (results) {
            total_scan[i] += results.meta.total_count;  

        });
        console.log(total_scan[i]);

        total = total + total_scan[i];

        $('#total').empty(total);
        $('#total').append(total);
        }
    }

Thanks for helping.

deanz
  • 166
  • 2
  • 14

0 Answers0