Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Run queued AJAX requests
$(function () {
//setup an array of AJAX options, each object is an index that will specify information for a single AJAX request
var ajaxes = [{ url : '<url>', dataType : 'json' }, { url : '<url2>', dataType : 'xml' }],
current = 0;
//declare your function to run AJAX requests
function do_ajax() {
//check to make sure there are more requests to make
if (current < ajaxes.length) {
//make the AJAX request with the given data from the `ajaxes` array of objects
url : ajaxes[current].url,
dataType : ajaxes[current].dataType,
success : function (serverResponse) {
// ...
//increment the `current` counter and recursively call this function again
//run the AJAX function for the first time once `document.ready` fires
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.