Here’s my codepen:
Here’s the relevant code:
for (var user in users) {
var current = users[user];
console.log(current);
$.ajax({
url: "https://wind-bow.glitch.me/twitch-api/streams/" + current, //replace 'streams' with 'channels' to get info for offline channels
type: "GET",
success: function(data) {
// console.log(JSON.stringify(data));
if (data.stream !== null) {
$(".container").append(
"<div class='row indiv'> <div class='col-md-1 emblem'><img class='logo' src=\"" +
data.stream.channel.logo +
"\"> </div> <div class='col-md-2'> <a href='#'>" +
data.stream.channel.display_name +
"</a></div> <div class='col-md-9'> <p>" +
data.stream.channel.status +
"</p> </div> </div>"
);
} else {
$.ajax({
url: "https://wind-bow.glitch.me/twitch-api/channels/" + current, //replace 'streams' with 'channels' to get info for offline channels
type: "GET",
success: function(data2) {
console.log(data2);
$(".container").append(
"<div class='row indiv'> <div class='col-md-1 emblem'><img class='logo' src=\"" +
data2.logo +
"\"> </div> <div class='col-md-2'> <a href='" +
data2.url +
" '>" +
data2.display_name +
"</a></div> <div class='col-md-9'> <p>Offline</p> </div> </div>"
);
}
});
}
}
});
}
If you look at the codepen, you can see that noobs2ninjas (the final name in the users
array) repeats for every user that is offline. Why is this happening?
- Is it normal to have an ajax call within an ajax call? Feels like it’s too nested and that i should be doing something else (and maybe it’s causing my initial problem?)