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.
Creates a new ajaxmanager and returns it. Takes a list of options:
Your constructed ajaxmanager knows the following methods:
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).
//and add an ajaxrequest
$.manageAjax.add('someAjaxProfileName', {
success: function(html) {
$('ul').append('<li>'+html+'</li>');
},
url: 'test.html'
});
//and add an ajaxrequest with the returned object
$.manageAjax.add({
success: function(html) {
$('ul').append('<li>'+html+'</li>');
},
url: 'test.html'
});
//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'
});
Destroys an existing Ajaxmanager. Any requests in progress are aborted and waiting requests are cleared.
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.
Tip: Open your Firebug-Console, log the XHR´s and click around.
If you find bugs please report them!!!