so I want a simple script, that shows, whether a user is online at twitch or not. I'm familiar with coding in general, but I have never really dealt with Callbacks. So this is my basic code.
jQuery(document).ready(function(){
var streamLink = 'http://api.justin.tv/api/stream/summary.json?channel=ReasNSC2&jsonp=?';
$.getJSON(streamLink, function(a) {
if (a.viewers_count != "0")
{
alert(true)
}else {
alert(false)
};
});
});
The code above works fine. I got the expected result. So now I want to use the result in my code. So my first thought is: Let's use return statments.
jQuery(document).ready(function(){
alert(getStatus())
});
function getStatus()
{
var streamLink = 'http://api.justin.tv/api/stream/summary.json?channel=ReasNSC2&jsonp=?';
$.getJSON(streamLink, function(a) {
if (a.viewers_count != "0")
{
return(true)
}else {
return(false)
};
});
}
So I "created" this. Won't work. I found many explanations on the internet and on stackoverflow but I couldn't extract something really helping me. Can someone give me a helping hand with this basic question?
I want to do the request and then proceed with it. Big thanks in advance :)