I am trying the new Twitch API and new to Jquery Ajax. I have successfully completed an Ajax request (for a list of top games) and output it on the console log and inspected the console results to ensure that the results are valid.
However, I am unable to parse the Json successfully into HTML for display:
1) The output shows 'undefined'
2) It is not iterating through the whole Json result set (shows 2 instead of 19 results)
Any advice? Thank you
New Twitch API reference: https://dev.twitch.tv/docs/api/reference/#get-top-games
<script>
$.ajax('https://api.twitch.tv/helix/games/top',
{
headers: {
"Client-ID": 'XXXXXXXXXXXXXXXXX'
},
dataType: 'json',
success: function ( data ) {
var content = '';
$.each(data, function(index, element){
content += 'id: ' + element.id + '<br />';
content += 'name: ' + element.name + '<br />';
$('#output').html(content);
});
}
})
.then(console.log);
</script>
</head>
<body>
<div id="output"></div>
</body>