October 22, 2024
Chicago 12, Melborne City, USA
PHP

When execute multiple ajax function in async way. PHP response in sync way


Here show js function, But my response received from PHP which is in sequence. So I expecting queries to execute all in one go.

PHP queries

public function get_filtered_data_01(){...}
public function get_filtered_data_02(){...}

JS query

//Example ajax query 01 as like below we have few more query
    function load_filtered_data_1(data_params) {
        $.ajax({.....});
    }
    async function loadAllFilters(data_params) {
        try {
            await Promise.all([
                load_filtered_data_1(data_params),
                load_filtered_data_2(data_params),
                ............
            ]);
        } catch (error) {
            console.error("Error loading filters:", error);
        }
    }
    $('#dropdown').on('change', async function() {
        // Load all other filters concurrently
        await loadAllFilters(data_params);
    });



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video