Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created October 2, 2012 10:25
Show Gist options
  • Save ajcrites/3818056 to your computer and use it in GitHub Desktop.
Save ajcrites/3818056 to your computer and use it in GitHub Desktop.
Ad-hoc jQuery Ajax Queue
function AjaxQueue () {
this.q = [];
}
AjaxQueue.prototype = {
push: function (options) {
options = $.extend({'complete': function () {}}, options);
var originalComplete = options.complete
var qa = this;
options.complete = function () {
qa.q = qa.q.slice(1);
originalComplete.apply(this.last, arguments);
if (qa.q.length) {
qa.last = jQuery.ajax(qa.q[0]);
}
}
qa.q.push(options);
if (qa.q.length == 1) {
qa.last = jQuery.ajax(options);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment