You can chain the two by putting the second JSON request in the callback of the first. This means that the second JSON request will be called after the first (which may be slightly slower), but is an easy way to get the received results in order.
For example:
$.getJSON("https://www.chain.so/api/v2/address/DOGE/DK1i69bM3M3GutjmHBTf7HLjT5o3naWBEk", function(data1) {
$.getJSON("https://www.chain.so/api/v2/address/DOGE/DLztFgLx33AMMiWFvLkbwy3cDdiuE9ZTrS", function(data2) {
var combinedText = data1.data.received_value + data2.data.received_value;
});
});
A slightly better approach, if you still want to send both JSON requests at the same time, is to have a callback that makes sure both requests are in before chaining the two together. This again preserves the order of the JSON requests.
This option is also neater, especially with more JSON requests, because you don't have to keep nesting them.
var data = [];
var numJsonRequests = 2;
function callback(index, data) {
// fill in data
data[index] = numJsonRequests;
// check that all requests are in
for(var i = 0; i < numJsonRequests; i++) {
if(data[i] === undefined) return;
}
// all json requests are in, do something with the combined data
var combinedData = data.join("");
}
// call callback from json requests
$.getJSON("https://www.chain.so/api/v2/address/DOGE/DK1i69bM3M3GutjmHBTf7HLjT5o3naWBEk", function(data) {
callback(data.data.received_value, 0);
});
$.getJSON("https://www.chain.so/api/v2/address/DOGE/DLztFgLx33AMMiWFvLkbwy3cDdiuE9ZTrS", function(data) {
callback(data.data.received_value, 1);
});