AJAX Queue/Cache/Abort/Block Manager v. 2.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:
- normal jQuery-Ajax-Options
- queue: (true|false|'clear') the queue-type specifies the queue-behaviour. The clear option clears the queue, before it adds a new ajax-task to the queue (last in first out)
- abortOld (true|false: aborts all "older" requests, if there is a response to a newer request
- maxRequests: (number (1)) limits the number of simultaneous request in the queue.
- preventDoubbleRequests (true|false): prevents multiple equal requests (compares url, data and type)
- cacheResponse (true|false): caches the response data of succesfull responses (The cache will affect all Ajaxmanagers)
Your constructed ajaxmanager knows three methods:
- add: ([uniqueName], options) returns an id of your XHR object and takes the following options:
- clear: ([uniqueName], [shouldAbort: true|false]) Clears the ajax queue of waiting requests. If the second parameter is true, all requests in proccess will be aborted, too.
- abort: ([uniqueName], [id]) Aborts all managed XHR-requests. If you pass the optional index number of your XHR object only this XHR will be aborted.
Example:
//create an ajaxmanager named cacheQueue
var ajaxManager = $.manageAjax.create('cacheQueue', {
queue: true,
cacheResponse: true
});
//and add an ajaxrequest with the returned function
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'
});
Demo:
Tip: Open your Firebug-Console, log the XHR´s and click around.
If you find bugs please report them!!!
Project Site & Bugtracker
Download
Licenses
Older version of the ajaxmanager (slightly different API)
Back to protofunc