Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
How to check if specific (not all) jQuery AJAX requests are finished

I have the following function which does some checks via ajax and enables/disables an add to cart button:

function formUpdate() {

    var data = {
        'action': 'my_action_name',
        'qty': $( '#qty' ).val(),
    };

    var request = jQuery.ajax({
        url: 'myajax.php',
        method: "POST",
        data: data,
        async: true
    });

    request.done( function( response ) {

        // I disable my add to cart button here
        // Some code that takes a while to run to determine if add to cart should be enabled
        // I conditionally enable the add to cart here based on the above

    }

}

$( '#qty' ).on( 'change', function() {

    formUpdate();

});

The request is triggered when #qty (number) field is changed, when a user presses the up/down arrows on the field or uses the up/down keys the ajax request is sent multiple times and because the code in the request.done takes a while if the requests near the end result in a disabled add to cart button there is a brief period where the previous requests keep it enabled until the later requests are done - so a user could add to cart in that brief moment.

I want to eliminate this from occurring, I know I can use async: false, but this stops the user from using up/down arrows/keys until the request is done.

What I'd like to do is keep async: true, but ensure the add to cart remains disabled until all requests are completed - I have tried disabling the add to cart before the ajax request in the formUpdate function but this doesn't appear to work, assumed because of all the ajax requests enabling/disabling the add to cart button.

I am wondering if there is a way I can use the action name I am passing in data for the ajax request, then have a function that disables the add to cart button until all of the ajax requests with that name are finished running.

I have looked around for code for this but most of what I have found is related to ALL ajax requests, not specific ones.

Is this possible or is there another solution?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!