Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Request Queueing in jQuery
- // Ensure on client side that one request is processed after the former has been completed
- // Any request should be automatically queued, with no changes in the $.post( ) and $.ajax( ) calls
- /* For this, register special queue functions in jQuery.ajaxSetup() :
- $.ajaxSetup({
- "beforeSend":ajaxQueue.beforeSend,
- "complete":ajaxQueue.complete
- })
- */
- var ajaxQueue = (function() {
- var q = [];
- var executingNext = false;
- return {
- beforeSend:function(jqXHR,opt) {
- if ($.active > 1 && ! executingNext ) {
- q.push(opt);
- executingNext = false;
- return false;
- }
- },
- complete:function() {
- if (q.length > 0) {
- var $next = q.shift( );
- executingNext = true;
- $.ajax( $next );
- }
- },
- get:function() { // --> for debug purposes
- return q;
- }
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement