Ajax Manager 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:
o normal jQuery-Ajax-Options
o ‘abort’ ([function]): a function that will be called, if the request is aborted
* 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:01 | //create an ajaxmanager named cacheQueue |
02 | var ajaxManager = $.manageAjax.create('cacheQueue', { |
03 | queue: true, |
04 | cacheResponse: true |
05 | }); |
06 | //and add an ajaxrequest with the returned function |
07 | ajaxManager.add({ |
08 | success: function(html) { |
09 | $('ul').append('<li>'+html+'</li>'); |
10 | }, |
11 | url: 'test.html' |
12 | }); |
13 | |
14 | |
or only with the uniqueName parameter
01 | //generate an ajaxmanger named clearQueue |
02 | $.manageAjax.create('clearQueue', {queue: 'clear', maxRequests: 2}); |
03 | //and add an ajaxrequest with the name parameter |
04 | $.manageAjax.add('clearQueue', { |
05 | success: function(html) { |
06 | $('ul').append('<li>'+html+'</li>'); |
07 | }, |
08 | url: 'test.html' |
09 | }); |
10 | |
Demo:
http://www.protofunc.com/scripts/jquery/ajaxManager/Download:
http://www.protofunc.com/scripts/jquery/ajaxManager/jquery.ajaxmanager.jsSource:
http://www.protofunc.com/scripts/jquery/ajaxManager/ Related Listings:
- Impromptu – prompt jQuery plugin for Forms jQuery Impromptu is an extention to help provide a more...
- jClock : jQuery Clock Plugin Simple clock – display 12-hour or 24-hour time notation, local...
- jQuery plugin – Tooltip Ajax Script The content of a tooltip is by default the title...
