title: How should I keep track of for loop index while using ajax to insert php data into object?
body: <p>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.</p>
  
  <p>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. </p>
  
  <p>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. </p>
  
  <p>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.</p>
  
  <pre><code>        var compilelist = [];
          var promises = [];
  
          for (i=0; i &lt; &lt;?php echo $rowcount ?&gt;; i++) {
              var getname = &lt;?php echo json_encode($followarray) ?&gt;[i];
              var getimg = &lt;?php echo json_encode($imgarray) ?&gt;[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);
          }
  </code></pre>