Created
October 15, 2011 21:46
-
-
Save fatihacet/1290200 to your computer and use it in GitHub Desktop.
Simple and easy jQuery AJAX queue implementation trying - this is draft version -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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