manageAjax jquery plugin

谭鹏云
2023-12-01

$.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 the following 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.
  • getXHR: ([uniqueName], id) Returns the XHR-Object, if it is already constructed or the queue-function

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'  
});

 类似资料:

相关阅读

相关文章

相关问答