AJAX Queue/Synch/Abort/Block Manager
Helps you to manage AJAX requests and responses (i.e. abort requests, block requests, order responses). It is inspired by the AJAX Queue Plugin and the AjaxQueue document in the jQuery-Wiki.
$.manageAjax
Creates a new $.ajaxManager and returns it. Takes a list of options:
- normal jQuery-Ajax-Options
- manageType: (string) the queue-type specifies the queue-behaviour (default: 'normal'):
- 'sync': synchronizes the incomming responses (callbacks) in the same order the requests were made
- 'queue': queues your AJAX-requests (you have to set the maxReq-Option)
- 'abortOld': aborts all "older" requests, if there is a response of a newer request
- 'normal': normal behvaiour
- maxReq: (number) limits the number of simultaneous request in the queue. If you don´t use 'queue' as your manageType, then older requests will be aborted. (default: 0 = unlimited requests)
- blockSameRequest: (boolean) prevents same request, compares url, data and type in the same queue to determine, wether the same request is already in process. (default: false)
Your constructed ajaxmanager knows two methods:
- $.ajaxManager.prototype.add: (options) returns the index number of your XHR object and takes the following options:
- $.ajaxManager.prototype.abort: ([number]) Aborts the managed XHR-requests. If you pass the optional index number of your XHR object only this XHR will be aborted.
Example:
var ajaxManager1 = $.manageAjax({manageType: 'abortOld', maxReq: 0});
ajaxManager1.add({
success: function(html) {
$('ul').append('<li>'+html+'</li>');
},
url: 'test.html'
});
Demo:
Tip: Open your Firebug-Console, log the XHR´s and click around.
Download
Licenses
Back to protofunc