I am trying to resolve a SoundCloud URL to a track ID, so I later on can use the track ID with SC.stream()
.
This code works, but since it's async it doesn't work with the rest of my code:
$.getJSON(
'http://api.soundcloud.com/resolve.json?url=' + trackUrl + '&client_id=' + clientId,
function(result) {
console.log('Track ID: ' + result.id);
setTrackId(result.id);
}
);
I'm trying to do the same thing with .ajax()
so it can be async, but I can't get that to work. Console shows a GET error.
Here's the code:
$.ajax({
url: 'http://api.soundcloud.com/resolve.json?url=' + trackUrl + '&client_id=' + clientId,
dataType: 'json',
async: false,
success: function(result) {
console.log('Track ID: ' + result.id);
setTrackId(result.id);
}
});
How can I get my ajax code to work? Or am I doing this all wrong? Tried to search for an answer but didn't find anything useful. Thanks.
EDIT: Here's the rest of my code: http://codepen.io/etzolin/pen/Jonqe