Append JSON data to table after every while loop iteration using JavasScript

The ‘add_txs_fnc’ function makes an ajax request to a PHP script which adds records to a database, and returns JSON data.

The JSON is displayed in the #display_table. I want data to be appended to the table on every loop iteration (so I can see the result of every function call in real time), but they all get appended simultaneously after the while loop has finished.

I assume I need to be using something like ‘async’, ‘await’ etc, but not sure how to proceed.

<div id="display_table"></div>

<script>
$(function() {
   while (true) {
      id_lkup_fnc(function(res) {
         add_txs_fnc(function(res) {
            let data = jsonDat2Array_fnc(res);
            createTable_fnc(data);
         });
      });
   }