AjaxQ jQuery Plugin

A tiny, simple jQuery plugin for sequential ajax requests.

Features

View Project On Github Just the JavaScript, Please

Usage

Using AjaxQ is easy. Add the plugin into your project, then instead of calling $.ajax(opts); call $.ajaxq(name, opts);

Any requests added with the same queue name will be processed sequentially. It is possible to have more than one queue running in parallel by using different queue names. See the demo below to see two queues running together at the same time.

$.ajaxq

    // See full $.ajax documentation.  The only difference is the first parameter (the queue name).
    $.ajaxq ("MyQueue", {
        url: 'http://jsfiddle.net/echo/jsonp/',
        type: 'post',
        dataType: "jsonp"
    });

$.postq

    // See full $.post documentation documentation.
    $.postq ("MyQueue", 'path/to/your/resource', onsuccess);

$.getq

    // See full $.get documentation documentation.
    $.getq ("MyQueue", 'path/to/another/resource', onsuccess);

$.ajaxq.isRunning()

    // Returns boolean representing whether there are any requests running (in any queue).
    
    $.getq ("MyQueue", 'path/to/another/resource', onsuccess);
    $.ajaxq.isRunning(); // Will return true since request just started.
    
    function onsuccess() {
        $.ajaxq.isRunning(); // Will return false since request is finished.
    }

$.ajaxq.clear(qname)

    // Aborts the current request, and clears the current queued items in the given queue.
    $.getq ("MyQueue", 'path/to/another/resource', onsuccess);
    $.getq ("MyQueue", 'path/to/another/resource', onsuccess);
    $.getq ("MyQueue", 'path/to/another/resource', onsuccess);
    
    // Will cancel the current request and clear future ones.
    $.ajaxq.clear("MyQueue"); 

Demo

Click the buttons below to add requests onto two separate queues. Requests for this demo are generated using the jsFiddle echo API.


Queue #1

Queue #2


About

AjaxQ was developed by Foliotek, Inc. for use in Foliotek Presentation. It is licensed under the MIT License. See the LICENSE file.

You can find some more of our code and projects on our development blog.