Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8663371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:58:20+00:00 2026-06-12T16:58:20+00:00

There is a useful plugin that Corey Frang posted on stackoverflow for queueing ajax

  • 0

There is a useful plugin that Corey Frang posted on stackoverflow for queueing ajax requests. In my case, it’s useful for loading up large collections of data in “chunks” so as to minimise user perceived slowness. It works perfectly, except when a pagination event is triggered before the queue of ajax requests has completed, in this case, the container holding the loaded objects will clear, but the queued requests will continue to run, resulting in undesired behaviour. What I would like is to find / learn of a way to clear the queue of all existing requests. The developer posted a way to do this, however, it doesn’t appear to work. I’ve tried reading up on .queue on the jQuery site, but I can’t seem to understand how to make this work. I have already spent a lot of time trying to figure out this problem, but perhaps my lack of familiarity with some of the more complex aspects of jQuery is holding me back. Hope that someone out there who is more familiar with jQuery can help 🙂 ( marked what was suggested and does not appear to work with some “!!!!!” )

/*
* jQuery.ajaxQueue - A queue for ajax requests
* 
* (c) 2011 Corey Frang
* Dual licensed under the MIT and GPL licenses.
*
* Requires jQuery 1.5+
*/ 
(function($) {

// jQuery on an empty object, we are going to use this as our Queue
var ajaxQueue = $({});

$.ajaxQueue = function( ajaxOpts ) {
    var jqXHR,
        dfd = $.Deferred(),
        promise = dfd.promise();

    // queue our ajax request
    ajaxQueue.queue( doRequest );

    // add the abort method
    promise.abort = function( statusText ) {

        // proxy abort to the jqXHR if it is active
        if ( jqXHR ) {
            return jqXHR.abort( statusText );
        }

        // if there wasn't already a jqXHR we need to remove from queue
        var queue = ajaxQueue.queue(),
            index = $.inArray( doRequest, queue );

        if ( index > -1 ) {
            queue.splice( index, 1 );
        }

        // and then reject the deferred
        dfd.rejectWith( ajaxOpts.context || ajaxOpts,
            [ promise, statusText, "" ] );

        return promise;
    };

    // run the actual query
    function doRequest( next ) {        
        jqXHR = $.ajax( ajaxOpts )
            .then( next, next )
            .done( dfd.resolve )
            .fail( dfd.reject );
    }

    return promise;
};

// !!!!!!!!!!!!!!!!!
// this is what the developer suggested on his website in the comments section
// ... but it does not appear to work
$.ajaxQueue.stop = function( clear ) { ajaxQueue.stop( clear ); }

})(jQuery);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:58:21+00:00Added an answer on June 12, 2026 at 4:58 pm

    Thank for your efforts in helping me to solve the problem. However..

    I have found a better ajax queue plugin – “ajaxq” by Oleg Podolsky, if you need to queue ajax requests (along with the ability to properly clear the queue), I recommend using this instead.

    Add to Queue:

    ajaxq('queue_name', {
        // standard $.ajax options
    });
    

    Stop / Clear Queue:

    ajaxq('queue_name');
    

    Plugin:

    /*
     * jQuery AjaxQ - AJAX request queueing for jQuery
     *
     * Version: 0.0.1
     * Date: July 22, 2008
     *
     * Copyright (c) 2008 Oleg Podolsky (oleg.podolsky@gmail.com)
     * Licensed under the MIT (MIT-LICENSE.txt) license.
     *
     * http://plugins.jquery.com/project/ajaxq
     * http://code.google.com/p/jquery-ajaxq/
     */
    
    jQuery.ajaxq = function (queue, options)
    {
        // Initialize storage for request queues if it's not initialized yet
        if (typeof document.ajaxq == "undefined") document.ajaxq = {q:{}, r:null};
    
        // Initialize current queue if it's not initialized yet
        if (typeof document.ajaxq.q[queue] == "undefined") document.ajaxq.q[queue] = [];
    
        if (typeof options != "undefined") // Request settings are given, enqueue the new request
        {
            // Copy the original options, because options.complete is going to be overridden
    
            var optionsCopy = {};
            for (var o in options) optionsCopy[o] = options[o];
            options = optionsCopy;
    
            // Override the original callback
    
            var originalCompleteCallback = options.complete;
    
            options.complete = function (request, status)
            {
                // Dequeue the current request
                document.ajaxq.q[queue].shift ();
                document.ajaxq.r = null;
    
                // Run the original callback
                if (originalCompleteCallback) originalCompleteCallback (request, status);
    
                // Run the next request from the queue
                if (document.ajaxq.q[queue].length > 0) document.ajaxq.r = jQuery.ajax (document.ajaxq.q[queue][0]);
            };
    
            // Enqueue the request
            document.ajaxq.q[queue].push (options);
    
            // Also, if no request is currently running, start it
            if (document.ajaxq.q[queue].length == 1) document.ajaxq.r = jQuery.ajax (options);
        }
        else // No request settings are given, stop current request and clear the queue
        {
            if (document.ajaxq.r)
            {
                document.ajaxq.r.abort ();
                document.ajaxq.r = null;
            }
    
            document.ajaxq.q[queue] = [];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any useful module on CPAN that returns number of biggest fractions of
Greetings, I am curious if there is any good plugin or project that allows
There are several useful answers on SO regarding prevention of brute forcing a password
There are two very useful functions in SLIME: slime-copy-or-inspect-presentation-at-mouse and slime-presentation-menu . But they
There are some very useful classes for working with images. I am stuck with
There's a feature of the Apple Objective-C language which is really useful to me:
Is there such macro in C++ (cross-compiler or compiler-specific): #if isclass(NameSpace::MyClass) Would be useful.
Google returns me just nothing useful on these keywords. But I know there is
For people out there using Haxe , what makes it useful for you? Reading
Here is the problem: I have a very complex plugin that does lots of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.