AJAX Queue/Cache/Abort/Block Manager v. 3.0

Helps you to manage AJAX requests and responses (i.e. abort requests, block requests, order requests). It is inspired by the AJAX Queue Plugin and the AjaxQueue document in the jQuery-Wiki.

$.manageAjax.create (uniqueName, options)

Creates a new ajaxmanager and returns it. Takes a list of options:

Your constructed ajaxmanager knows the following methods:

Note:

First you have to construct/configure a new Ajaxmanager

//create an ajaxmanager named someAjaxProfileName var someManagedAjax = $.manageAjax.create('someAjaxProfileName', { queue: true, cacheResponse: true });

You have two different ways to call your methods (don´t mix them).

Calling Ajaxmanager with uniqueName

//and add an ajaxrequest $.manageAjax.add('someAjaxProfileName', { success: function(html) { $('ul').append('<li>'+html+'</li>'); }, url: 'test.html' });

Calling Ajaxmanager with the returned ajaxmanger-Object

//and add an ajaxrequest with the returned object $.manageAjax.add({ success: function(html) { $('ul').append('<li>'+html+'</li>'); }, url: 'test.html' });

Example:

//create an ajaxmanager named cacheQueue var ajaxManager = $.manageAjax.create('cacheQueue', { queue: true, cacheResponse: true }); //and add an ajaxrequest with the returned object ajaxManager.add({ success: function(html) { $('ul').append('<li>'+html+'</li>'); }, url: 'test.html' });

or only with the uniqueName parameter

//generate an ajaxmanger named clearQueue $.manageAjax.create('clearQueue', {queue: 'clear', maxRequests: 2}); //and add an ajaxrequest with the name parameter $.manageAjax.add('clearQueue', { success: function(html) { $('ul').append('<li>'+html+'</li>'); }, url: 'test.html' });

$.manageAjax.destroy (uniqueName)

Destroys an existing Ajaxmanager. Any requests in progress are aborted and waiting requests are cleared.

Events/Callbacks:

The ajaxmanager adds some new events or enhances some existing callbacks.

name arguments new/enhanced
beforeCreate (local) XHR-ID, options new
beforeSend (local) XMLHttpRequest, options enhanced: options arguments is passed
managerName + 'AjaxStart' (global) event new
complete (local) xhr*, status, options enhanced: the options arguments is additionally passed.
managerName + 'AjaxComplete' (global) event, xhr*, status, options new
managerName + 'DOMComplete' (DOM-Event**) event, xhr*, status, options new
'DOMComplete' (DOM-Event**) event, xhr*, status, options new
success (local) data, textStatus, xhr*, options enhanced: the options arguments is additionally passed.
managerName + 'AjaxSuccess' (global) event, xhr, options, data new
managerName + 'DOMSuccess' (DOM-Event**) event, data, options new
'DOMSuccess' (DOM-Event**) event, data, options new
managerName + 'AjaxStop' (global) event new

*Note: If the cacheResponse - option is true, the xhr-argument can be an empty object.

**Note: You need to configure 'domCompleteTrigger' / 'domSuccessTrigger' to trigger these events.

Demo:

Tip: Open your Firebug-Console, log the XHR´s and click around.

{queue: true}

0 secound delay | 1 secound delay | 2 secounds delay | 3 secounds delay |

{queue: 'clear', maxRequests: 2, abortOld: true}

0 second delay | 1 second delay | 2 seconds delay | 3 secounds delay |

{queue: 'clear', cacheResponse: true}

0 second delay | 1 second delay | 2 seconds delay | 3 secounds delay |

{queue: false, cacheResponse: true, preventDoubleRequests: false}

0 second delay | 1 second delay | 2 seconds delay | 3 secounds delay |

If you find bugs please report them!!!

Project Site & Bugtracker

Download

Licenses

Back to protofunc