public
Last active

  • Download Gist
parallel.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
var results = {};
var requests = 0;
 
var urls = ["values/1", "values/2", "values/3"];
 
$.each(urls, function(url) {
$.getJSON(url, function(data) {
results[url] = data.value;
++requests;
 
 
if (requests == 3) {
$('#mynode').html( results[urls[0]] / results[urls[1]] * results[urls[2]]);
}
});
});
 
serial.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$.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);
});
 
});

Error in line 6 of parallel.js, see forked copy at https://gist.github.com/jamiesonbecker/5077534 for fix.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.