I got a problem with my Json in Javascript. So I run json and I get a list of all youtube id's, now I show all those youtube videos and I place a button next to it. Now if I click that button it must give me a console log of the youtube id of that video but it always gives me the last youtube video id. Can anyobdy help me witht his code cause Im stuck.
Here is my code:
function generateLast5()
{
$("#musicList").html("");
console.log("what uuup");
$.ajax({
url: ".............",
dataType: "jsonp",
success: function(json){
console.log(json.played_tracks);
for(i in json.played_tracks)
{
console.log(i);
oSingle = json.played_tracks[i];
console.log(oSingle.youtube_ids.default);
phli = $("<li/>")
.appendTo("#musicList");
$("<iframe/>")
.attr("src", "http://www.youtube.com/embed/" + oSingle.youtube_ids.default)
.appendTo(phli);
$("<button/>")
.attr("id","btnAddToPlaylist")
.text("Add To Playlist")
.click(function() {
console.log(oSingle.youtube_ids.default);
})
.appendTo(phli);
}
}
});
}