I am making a website with an API to gather artist/song information (MusixMatch) along with the YouTube API. My goal is to output certain data to the screen for each search result and show a related youtube video. The formatting for each result is fine and the first AJAX call outputs it correctly. The issue is that I have nested the Youtube API within the MusixMatch API so that I can run the video search queries with the artist data. That works fine and I can get the video to display but for some reason I cannot get it to display in the div I created for each result.
$.ajax({
type: "GET",
data: {
apikey:"85f6c6b42df5d50c164d2e47183cb357",
q_track: songSearch,
f_has_lyrics: 1,
s_artist_rating: "desc",
s_track_rating: "desc",
format:"jsonp",
callback:"jsonp_callback"
},
url: "https://api.musixmatch.com/ws/1.1/track.search",
dataType: "jsonp",
jsonpCallback: 'jsonp_callback',
contentType: 'application/json',
success: function(data) {
console.log(data);
var live = 'Live';
var remaster = 'Remaster';
var edit = 'Edit';
var myHTML = '';
for (var i = 0; i < data.message.body.track_list.length; i++) {
if ((data.message.body.track_list[i].track.track_name).search(live) > 0 || (data.message.body.track_list[i].track.track_name).search(remaster) > 0 || (data.message.body.track_list[i].track.track_name).search(edit) > 0){
continue;
}
myHTML += '<li class="artistName list-group-item">';
myHTML += '<span class="name">' + data.message.body.track_list[i].track.track_name + '</span></br>';
myHTML += '<span class="rating">Artist Name: ' + data.message.body.track_list[i].track.artist_name + '</span></br>';
$('#song_output').append(myHTML);
myHTML = '';
$.ajax({
type: "GET",
data: {
part: "snippet",
key: 'AIzaSyBYLyCoBwVBnxICX2w38cnO_kkoQzW09Ko',
maxResults: 1,
q: data.message.body.track_list[i].track.track_name + ' ' + data.message.body.track_list[i].track.artist_name ,
},
url: "https://www.googleapis.com/youtube/v3/search",
dataType: "JSON",
contentType: 'application/json',
success: function(data) {
console.log(data);
var video = 'data.items[0].id.videoId';
postVideo(video);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
},
complete: function(){
}
})
function postVideo(video){
myHTML += '<iframe width="560" height="315" src="https://www.youtube.com/embed/' + video + '" frameborder="0" allowfullscreen></iframe></br>';
myHTML += '</div>'
myHTML += '</li>';
}
}
$('#song_output').append(myHTML);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
},
complete: function(){
$("#ajaxIndicator").modal('hide');
}
})
Sorry if this is not enough information but I can provide more if needed. Does anyone have an idea of what could be causing the to display outside of the div instead of inside of it despite it being output within it?