I don't succeed with outputting this text before executing ajax. I know it has something to do with async/await, but after reading other posts and articles I still can't figure it out. Anyone able to help me with providing an updated code?
This is the output (Calculating now...) I want before execution:
$(this).parent('td').parent('tr').find('td span.google').text('Calculating now...');
Full code:
$(function(){
        $('.calculate').click(function(){
            $(this).parent('td').parent('tr').find('td span.google').text('Calculating now...');
            
            var total_distance = 0;
            $(this).parent('td').parent('tr').find('td span.tripleg').each(function() {
                var origin = $(this).attr('origin');
                var destinations = $(this).attr('destinations');
                $.ajax({
                    type: "GET",
                    url: 'includes/calculate_distance.php?action=distance_analysis',
                    data: {"origin": origin, "destinations": destinations, "google_api_key": google_api_key},
                    async: false,
                    success: function(result) {
                        total_distance = total_distance + parseFloat(result);
                    }
                });
            });
            $(this).parent('td').parent('tr').find('td span.google').text(total_distance.toFixed(2));
        });
    });
Many thanks in advance!
