Im storing track IDs in a database that are used as playlists.
The track ID data is retrieved using jQuery $.get() and is returned in a JSON array.
Next a jQuery $.each() loops a SC.get(‘/tracks/’) that is passed the relevant track id.
$.each(pl_array.track, function(i) {
var pl_track_id = '/tracks/' + pl_array.track[i].id;
SC.get(pl_track_id,function (tracks) {
//looped code here
});
});
The problem is the SC.get() call is asynchronous, and will result in the tracks being ordered randomly. The jQuery $.get() has the option to disable asynchronous and run synchronously. Is there any way i can do somthing like this with the SC.get() function or is there another option?
Don’t do that.
SJAX freezes the browser and is extremely annoying.
If you really want synchronous processing, use recursion instead of a loop:
However, it would be much faster to send all the requests at once (the way you’re doing now), then sort the results after they all come in.