This question already has an answer here:
I am pulling data from a JSON file using $.getJson. This data is assigned to the variables gameType, host, and port. Then another $.getjson makes a request using the data pulled from the first json file. The JSON data being requested in the FOR Loop is data being queried from source game servers.
See this link for an example of the data received from a query
The FOR loop is to iterate over the multiple servers that need to be queried. I am trying to take all the data that is received from all the queries that are made, and assign it to a my array "now". I believe the problem is my misunderstanding of the scope, but i'm not too sure. Thanks for any insight you can give me.
var now = Array();
$.getJSON("http://ift.tt/1Rngi0D", function(response, $scope) {
var arr = response.servers;
for(var i = 0; i < arr.length; i++) {
var gameType = arr[i].gametype;
var servHost = arr[i].host;
var servPort = arr[i].port;
$.getJSON("http://ift.tt/1PwDUMt"+gameType+"&host="+servHost+"&port="+servPort, function(data, $scope) {
var html = "";
html += "<tr>";
html += "<td>" + data.game_dir + "</td>";
html += "<td>" + data.hostname + "</td>";
html += "<td>" + data.gq_address + ":" + data.gq_port + "</td>";
html += "<td>" + data.map + "</td>";
html += "<td>" + data.num_players + "/" + data.max_players + "</td>";
html += "</tr>";
now[i]=data;
$("#server-data tbody").append(html);
});
}
console.log(now);
});
Aucun commentaire:
Enregistrer un commentaire