Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fatihacet
Created October 15, 2011 21:46
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fatihacet/1290200 to your computer and use it in GitHub Desktop.
Save fatihacet/1290200 to your computer and use it in GitHub Desktop.
Simple and easy jQuery AJAX queue implementation trying - this is draft version -
$.ajaxQueue = [];
var que = $.ajaxQueue;
$.ajaxSetup({
beforeSend: function(){
if (this.queue) {
que.push(this);
}
else {
return true;
}
if (que.length > 1) {
return false;
}
},
complete: function(){
que.shift();
var newReq = que[0];
if (newReq) {
// setup object creation should be automated
// and include all properties in queued AJAX request
// this version is just a demonstration.
var setup = {
url: newReq.url,
success: newReq.success
};
$.ajax(setup);
}
}
});
// Fire more than one AJAX request at the same time.
$.ajax({
queue: true,
url: '/',
success: function(data) {
console.log('succeed');
}
});
$.ajax({
queue: true,
url: '/a',
success: function(data) {
console.log('succeed');
}
});
$.ajax({
queue: true,
url: '/mol',
success: function(data) {
console.log('succeed');
}
});
$.ajax({
queue: true,
url: '/kol',
success: function(data) {
console.log('succeed');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment