I’m having an issue looping through json.
In the below code the looped urls are out of order and the id in the alert is always 3. Can someone tell me what I’m doing wrong here?
var urls = ["http://soundcloud.com/disclosuremusic/sets/the-face-ep-1", "http://soundcloud.com/skibsthekid/sets/the-pink-slip", "http://soundcloud.com/disclosuremusic/sets/the-face-ep-1"];
for (var i = 0, url; url = urls[i]; i++) {
console.log(i);
$.getJSON('http://api.soundcloud.com/resolve?url=' + url + '&format=json&consumer_key=' + consumer_key, function(playlist) {
alert(i + playlist.title);
});
}
1 Answer