0

Here is my JS code:

for (var i in loadFile) {
        var count = 1;
        if(i != 0){
            $.ajax({
                'global': 'false',
                'type': "GET",
                'dataType': 'json',
                'data': {
                    0: loadFile[i][0],
                    1: loadFile[i][1],
                    2: loadFile[i][2]
                },
                'url': "<?php echo base_url();?>/config/export_import_taches/get_check_statut_tache.php",
                'success': function (data) {
                    var rowStatus = data;
                    dataTable2.row.add(
                    [
                        rowStatus,
                        loadFile[count][0],
                        loadFile[count][1],
                        loadFile[count][2]
                    ]
                    ).draw();
                    count = count + 1;
                }
            });

            $('#div_table_loadfile').show();        
        }
    }

I would like to be able to "stop" the program until the Ajax call is completed. Because my script automatically goes to the next record even without the response and this is causing me problems... Thanks in advance.

TheoB
  • 1
  • 3
  • Just `await` it – VLAZ Aug 31 '23 at 15:56
  • Aside from the issue, note that making AJAX calls in a loop is generally a *really* bad idea - you'll end up flooding your own server with requests. I would strongly suggest you make 1 request which returns all necessary data instead. – Rory McCrossan Aug 31 '23 at 16:04

0 Answers0