jQuery的两个循环超时

I'm work on script that will send ajax post to another page, i need to make two for loops before send ajax request with time out, one of them send successcfully but when make another loop it send all requests same time and make the server down:

     $("#me").on("click", function (event) {
                event.preventDefault();

       var lines = $('#emails').val().split('
');


       var sendToServer = function(lines, index){
       item = lines[index];
       if (item.trim().length != 0){

         for(idd = 1; idd <= 100; idd++){  
         $.ajax({
           type: 'POST',
           url: 'inc/save.php',
           data: { users : lines[index] , id : idd  },
           success: function(msg){
                $('#result').append(msg);


             if (index < lines.length) {
               setTimeout(
                 function () { sendToServer(lines, index+1); },
                 5000 // delay in ms
               );
             }
           }


         });

         }

       }
       else { sendToServer(lines, index+1); }
    };

    sendToServer(lines, 0);




            });

This code will delay a specified amount of time between every request

$("#me").on("click", function (event) {
    event.preventDefault();

    var lines = $('#emails').val().split('
');
    var requestDelay = 5000;
    var sendToServer = function (index) {
        item = lines[index];
        if (item.trim().length != 0) {
            var max = 100;
            var sendOne = function (idd) {
                $.ajax({
                    type: 'POST',
                    url: 'inc/save.php',
                    data: {
                        users: lines[index],
                        id: idd
                    },
                    success: function (msg) {
                        $('#result').append(msg);
                        if (idd <= max) {
                            setTimeout(sendOne, requestDelay, idd + 1);
                        } else {
                            if (index < lines.length) {
                                setTimeout(sendToServer, requestDelay, index + 1);
                            }
                        }
                    }
                });
            };
            sendOne(1);
        }
    };
    sendToServer(0);
});

It's set to 5000 requestDelay - but you could probably reduce that significantly

A "modern" code version using async/await and the fact that jquery.ajax returns a thenable

$("#me").on("click", async function (event) {
    event.preventDefault();
    const requestDelay = 5000;
    const wait = result => new Promise(resolve => setTimeout(resolve, requestDelay, result));

    const getIdd = async users => {
        for ( let id = 1; id <= 100; ++id) {
            const msg = await $.ajax({
                type: 'POST',
                url: 'inc/save.php',
                data: { users, id }
            });
            $('#result').append(msg);
            await wait();
        }
    };
    const lines = $('#emails').val().split('
');
    for (let line of lines) {
        await getIdd(lines);
    }
});