javascript - Why does SoundCloud API cause the loop to list data in different orders -
i made json file store soundcloud urls. $.each()
load data of json file , based on data gather more data soundcloud api. somehow since soundcloud causes loop load data in random orders, not way in json file.
here code data , soundcloud bit:
$.getjson("http://www.json-generator.com/api/json/get/bljohiysay?indent=2", function(data){ //link of playlist $.each(data.playlistarray, function(key, val){ //navigate array called playlistarray var songlink = val.url; // value of url in array sc.get('/resolve', { url: songlink }, function(track) { //convert soundcloud urls ids data. $("#demo").append("<p id= "+ track.id + ">" + track.title + "</p>"); }); }); });
the order correct when load data without having soundcloud code in loop. soundcloud each time refresh pages, order different. have @ demo please: http://jsfiddle.net/fq2rw/
on jsfiddle please run code copple of times , see order changes each time. why that? idea? or different way loop through json?
your code looping through each sc.get
doesn't wait sc.get
finish. hence order different each time it's reloaded.
i change use callback parameter of sc.get
loading next url.
on further thought, suggest using jquery deferred function chain events.
please see post: soundcloud javascript api sc.get() not allow me change variable outside of function
Comments
Post a Comment