manageAjax jquery plugin

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值