Skip to content

Instantly share code, notes, and snippets.

@perpetual-hydrofoil
Forked from paul/parallel.js
Last active October 9, 2018 15:22
Show Gist options
  • Save perpetual-hydrofoil/5077534 to your computer and use it in GitHub Desktop.
Save perpetual-hydrofoil/5077534 to your computer and use it in GitHub Desktop.
fixed typo in $.each statement. (otherwise each url will be a numeral: 0,1,2..)
var results = {};
var requests = 0;
var urls = ["values/1", "values/2", "values/3"];
$.each(urls, function(idx, url) {
$.getJSON(url, function(data) {
results[url] = data.value;
++requests;
if (requests == 3) {
$('#mynode').html( results[urls[0]] / results[urls[1]] * results[urls[2]]);
}
});
});
$.getJSON("/values/1", function(data) {
// data = {value: 1}
var value_1 = data.value;
$.getJSON("/values/2", function(data) {
// data = {value: 42}
var value_2 = data.value;
var sum = value_1 + value_2;
$('#mynode').html(sum);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment