Hey, I just want to write a function which gives the ID of the Stream back with return but everything I try, i cant return the ID. Maybe a logic mistake of myself …
Name = Streamname
channelID = holds the ID
function live(Name) {
var clientID_ = "XYZ";
var channelID = 0;
$.ajax({
method: "GET",
url: "https://api.twitch.tv/kraken/users/" + Name + "?client_id=" + clientID_,
}).done(function(channel) {
channelID = channel._id;
})
return ID;
}
function live(Name, callback) {
var clientID_ = "XYZ";
var channelID = 0;
$.ajax({
method: "GET",
url: "https://api.twitch.tv/kraken/users/" + Name + "?client_id=" + clientID_,
}).done(function(channel) {
callback(channel._id);
})
}
Then you’d call it like:
live ("some name", function (id) {
console.log(id);
});
But remember again, ajax is async, so your program will carry on doing whatever after it and the callback function will be executed once the request has been completed.