在使用ajax将php数据插入对象时,我应该如何跟踪for循环索引?

Ok so I'm pretty much completely new to using ajax and I'm also still in the process of understanding effective implementation of php. Been a bit stuck recently because I feel like I'm forgetting or overlooking a really easy solution.

Right now the following code gets a trove api query with the help of php and appends 100 of these queries for each item (I know it's inefficient but right now I have a reason for this method). I use 'getperson' to grab the name from the object's own data and then for each I assign the relevant value to all items.

I want to do the same for a img url, however I don't have a good enough understanding of ajax syntax or possibilities to properly pass the correct index (which matches the getname index) into the ajax function.

I feel like there was a much more efficient way to do this, but would prefer if anyone could help explain the steps I can take to iterate on my current model.

        var compilelist = [];
        var promises = [];

        for (i=0; i < <?php echo $rowcount ?>; i++) {
            var getname = <?php echo json_encode($followarray) ?>[i];
            var getimg = <?php echo json_encode($imgarray) ?>[i];
            var getitem = Geturl(getname, 100);
            var promise = $.getJSON(getitem);
            $.when(promise).done (function(data) {
                var getperson = data.response.query;
                $.each(data.response.zone[0].records.article, function(index, value) {
                    value.name = getperson;
                    // This is what I want to do but I can't grab from the loop cause 'each' is inside the ajax query
                    value.img = getimg; 
                    compilelist.push(this);
                });
            });
            promises.push(promise);
        }

Well this question was dumb anyway but I quickly found a messy solution if anyone ever has a similar problem, I just stored img var in array parallel to name array so that I could select index from the name and use it to grab img from php:

            var compilelist = [];
            var promises = [];
            for (i=0; i < <?php echo $rowcount ?>; i++) {
                var getname = <?php echo json_encode($followarray) ?>[i];
                var getitem = Geturl(getname, 100);
                var promise = $.getJSON(getitem);
                $.when(promise).done (function(data) {
                    var getperson = data.response.query;
                    var getindex = <?php echo json_encode($followarray) ?>.indexOf(getperson);
                    $.each(data.response.zone[0].records.article, function(index, value) {
                        value.name = getperson;
                        value.imgurl = <?php echo json_encode($imgarray) ?>[getindex];
                        compilelist.push(this);
                    });
                });
                promises.push(promise);
            }