When faced with a challenging problem, I persist through multiple attempts and seek your assistance in finding a solution.
My current goal is to populate a table with the number of viewers for a specific streamer using the Twitch API.
To achieve this, I carefully construct my ajax call:
viewerCount(streamer){
let viewers = [];
let streamerList = streamer;
for (let i = streamer.length-1; i >= 0; i--){
$.ajax({
type: 'GET',
url: 'https://api.twitch.tv/helix/streams?user_login='+streamerList[i]+'',
dataType:'JSON',
headers: {
"Client-ID": 'bgbezb2vov7jc4twxauhw3yh30ubbx',
"Authorization": "Bearer "+this.auth
},
success: function(data) {
viewers.push([i, streamerList[i], data['data'][0]['viewer_count']])
},
error: function(data){
console.log(data)
}
})
};
}
Once I have gathered the results, I populate my table. However, I encounter an issue where I wish to wait for all ajax calls to complete before displaying the information. I attempted to use promise.all without success.
I appreciate any help you can provide on this matter.