var urls = [];
//Make a bunch of URLs, use delay= to make them take time to load.
for (var i = 0; i < 10; i++) {
var n = Math.floor(Math.random() * 5);
urls.push("http://jsfiddle.net/echo/jsonp/?delay=" + n + "&data=" + i);
}
//Start all of the AJAX requests at once and store their deferreds in an array.
var defs = $.map(urls, function(url, i) {
log("Starting number " + i);
return $.ajax({
url: url,
dataType: "jsonp",
success: function() {
log("Finished number " + i);
}
});
});
//Slightly tricky part because you can't just do $.when(defs)
//This basically does $.when(defs[0], defs[1], defs[2], ...)
$.when.apply($, defs).done(function() {
log("Last one finished!");
});
function log(msg) {
$("<div>", { text: msg }).appendTo("body");
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.