Looping with a couple of ajax calls

Looping with a couple of ajax calls

Hi,
I've got an issue trying to get two ajax calls to loop and work together.
the first ajax call gets the title from a group of items and the second ajax call gets an array of tests.
so I want the web page to show the title and the first set of tests together then the second title and the second set of tests and so on.

Title1
a-test1
b-test2
c-test3

Title2
d-test1
e-test2
f-test3

I just can't seen to get it right.

Thanks

Code below


   for (var i = 0; i < listReleasesid.length; i++) {
      console.log('list releases id ' + listReleasesid[i]);
      var geteachrelease = "https://vsrm.dev.azure.com/" + organization + "/" + projectName + "/_apis/release/releases/" + listReleasesid[i] + "?api-version=5.0";
      console.log('get each release' + geteachrelease);

      $.ajax({
         url: geteachrelease,
         type: "GET",
         dataType: 'JSON',
         async: false,
         crossDomain: true,

         beforeSend: function (xhr3) {
            xhr3.setRequestHeader('Authorization', make_base_auth(username, password));
            xhr3.setRequestHeader('Access-Control-Allow-Headers', '*');
            xhr3.setRequestHeader('Access-Control-Allow-Origin', '*');
            console.log('function xhr3 ok');
         },

         success: function (geteachreleaseResp) {
            var geteachreleaseResults = JSON.stringify(geteachreleaseResp);

            console.log(geteachreleaseResp.id, geteachreleaseResp.name,geteachreleaseResp.environments[0].id, geteachreleaseResp.environments[0].name);
            //for (i in geteachreleaseResp.value) {


   // $('#each_Release_data').append(geteachreleaseResults);
itemtest.length=0;
star = "<h2>"+ geteachreleaseResp.name +"</h2>"; 
 itemtest.push(geteachreleaseResp.name); 
 itemtest.push(geteachreleaseResp.id); 
itemtest.push(geteachreleaseResp.environments[0].id);
itemtest.push(geteachreleaseResp.environments[0].name);
console.log("itentest",itemtest);
 environmentid.push(geteachreleaseResp.environments[0].id);




    var getReleaseTests = "https://vstmr.dev.azure.com/" + organization + "/" + projectName + "/_apis/tcm/resultdetailsbyrelease?releaseId=" + itemtest[1] +"&releaseEnvId=" + itemtest[2] + "&publishContext=CD&groupBy=TestRun&%24filter=Outcome+eq+Aborted%2CFailed&shouldIncludeResults=true&queryRunSummaryForInProgress=false";
      console.log( getReleaseTests);
console.log("title",itemtest[0]);
       $.ajax({
         url: getReleaseTests,
         type: "GET",
         dataType: 'JSON',
         async: false,
         crossDomain: true,

         beforeSend: function (xhr3) {
            xhr3.setRequestHeader('Authorization', make_base_auth(username, password));
            xhr3.setRequestHeader('Access-Control-Allow-Headers', '*');
            xhr3.setRequestHeader('Access-Control-Allow-Origin', '*');
            console.log('function xhr3 ok');
         },

         success: function (getReleaseTestsResp) {
            var getReleaseTestsResults = JSON.stringify(getReleaseTestsResp);

getReleaseTestsResp.resultsForGroup.forEach(resultsForGroup=>{
    console.log(
        'ID:', resultsForGroup.groupByValue.id,
        'Name: ', resultsForGroup.groupByValue.name,
        'Completed: ', resultsForGroup.groupByValue.state,
        'Date Ran: ', resultsForGroup.groupByValue.completedDate,
       'Passed: ', resultsForGroup.resultsCountByOutcome.Passed.count,
        'Failed: ', resultsForGroup.resultsCountByOutcome.Failed.count,
'Total Tests: ', (resultsForGroup.resultsCountByOutcome.Passed.count + resultsForGroup.resultsCountByOutcome.Failed.count)
    )

  tests.push("<div class=\"card-body\">"

 + "<h5>" + "Test Name: " + resultsForGroup.groupByValue.name + "</h5>" + 
"<h5>" + "Test ID: " + resultsForGroup.groupByValue.id + "</h5>" +
"<h5>" + "Completed: " + resultsForGroup.groupByValue.state + "</h5>" +
"<h5>" + "Passed: " + resultsForGroup.resultsCountByOutcome.Passed.count + "</h5>" +
"<h5>" + "Failed: " + resultsForGroup.resultsCountByOutcome.Failed.count + "</h5>" +
"<h5>" + "Total Tests: " + (resultsForGroup.resultsCountByOutcome.Passed.count + resultsForGroup.resultsCountByOutcome.Failed.count) + "</h5>" +
"</div>")

})

   console.log(getReleaseTestsResults);
   console.log(getReleaseTestsResp.resultsForGroup.groupByValue);


                 } // success
                               }); // ajax close

         
         
         } // success
        }); // ajax close
   
   
   } // for loop

$('#ryss').append(star);

$('#itemtest_data').append(tests);


end of code
Thanks
Russ