4 * Homepage: http://jquery.com/plugins/project/ajaxqueue
5 * Documentation: http://docs.jquery.com/AjaxQueue
14 success: function(html){ jQuery("ul").append(html); }
18 success: function(html){ jQuery("ul").append(html); }
22 success: function(html){ jQuery("ul").append("<b>"+html+"</b>"); }
26 success: function(html){ jQuery("ul").append("<b>"+html+"</b>"); }
30 <ul style="position: absolute; top: 5px; right: 5px;"></ul>
34 * Queued Ajax requests.
35 * A new Ajax request won't be started until the previous queued
36 * request has finished.
40 * Synced Ajax requests.
41 * The Ajax request will happen as soon as you call this method, but
42 * the callbacks (success/error/complete) won't fire until all previous
43 * synced requests have been completed.
51 var pendingRequests
= {};
56 $.ajax = function(settings
) {
57 // create settings for compatibility with ajaxSetup
58 settings
= jQuery
.extend(settings
, jQuery
.extend({}, jQuery
.ajaxSettings
, settings
));
60 var port
= settings
.port
;
62 switch(settings
.mode
) {
64 if ( pendingRequests
[port
] ) {
65 pendingRequests
[port
].abort();
67 return pendingRequests
[port
] = ajax
.apply(this, arguments
);
69 var _old
= settings
.complete
;
70 settings
.complete = function(){
72 _old
.apply( this, arguments
);
73 jQuery([ajax
]).dequeue("ajax" + port
);;
76 jQuery([ ajax
]).queue("ajax" + port
, function(){
81 var pos
= synced
.length
;
84 error
: settings
.error
,
85 success
: settings
.success
,
86 complete
: settings
.complete
,
96 settings
.error = function(){ syncedData
[ pos
].error
= arguments
; };
97 settings
.success = function(){ syncedData
[ pos
].success
= arguments
; };
98 settings
.complete = function(){
99 syncedData
[ pos
].complete
= arguments
;
100 synced
[ pos
].done
= true;
102 if ( pos
== 0 || !synced
[ pos
-1 ] )
103 for ( var i
= pos
; i
< synced
.length
&& synced
[i
].done
; i
++ ) {
104 if ( synced
[i
].error
) synced
[i
].error
.apply( jQuery
, syncedData
[i
].error
);
105 if ( synced
[i
].success
) synced
[i
].success
.apply( jQuery
, syncedData
[i
].success
);
106 if ( synced
[i
].complete
) synced
[i
].complete
.apply( jQuery
, syncedData
[i
].complete
);
109 syncedData
[i
] = null;
113 return ajax
.apply(this, arguments
);