Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.