Looking for a better way to handle an ajax script that pulls in post data on click

You ajax logic seems okay.. In order to solve a duplication problem you need to add a flag.

Example:

var isLoading = false;

-- Your click event is here --

// Only let things to happen if there's no ajax in the middle of process
if( isLoading == false ) {

    // Set it to true - now nothing happens if you click it again
    isLoading = true;

    -- All your ajax logic here --

    // Complete triggers in both cases: "success" or "error"
    complete: function() {

        // Ajax is now done, let's let user to trigger another one if he/she wants
        isLoading = false;
    }
}

Unfortunately ajax in WordPress is not the fastest thing on Earth. WordPress has a lot of junk in the trunk and it needs to load considerable amount of scripts, even with ajax calls.

Try searching online, there might be few tricks and tips to speed up WordPress ajax..

Leave a Comment