It really bugs me that I can’t find the solution - I’m not even sure where to look.
I can have the offline/online status but it doesn’t iterate through all users, which means I get the same status for everybody (i.e. online OR offline).
Another weird thing is that sometimes it will be ALL offline, sometimes ALL offline.
I suppose it has to do that the offline/online status in my function isn’t linked to a particular user. I’ve tried to solve that (for loops, nested Ajax, …) but to no avail.
I do make an Ajax request for streams (the second Ajax request in my code), but I think it’s in the wrong place and so it doesn’t iterate properly and doesn’t return the appropriate status offline/online for each user.
Oh dear, you’re right… but I have 2 For loops and 2 ajax requests - now I’m totally confused as to where I should put any of it. When I get lost like that I usually start from scratch again - but I’ve already done that three times.
[Edit] Wait, wait, ok, I’m gonna get this maybe not tonight but that’s fine, I just wanted something I could work with and I can work on that.
I’ll definitely have a look at that later - but not this time ! Just for the three apps I’ve had to watch Intro to Ajax, Intro to jquery, and some videos on Youtube and I actually like it (ajax)… I’m not strong enough to stray so soon ! But thank you for the info.
Ok I think it’s clearer in my head with this last explanation. Yes, I think it is (sorry, I’m thinking and writing at the same time).
Thanks a lot - I really hope I can fix it now.
[edit] it’s just…I find it really puzzling that I can something in a for loop, and that a function outside that will “recognize” my i. Damn it I’ve got to continue reading YDKJS .
Don’t look at this if you want to figure it out yourself! Its just a quick demo of how to pass info between functions.
[details=Summary]You see in this loop, I iterate the array and then use that info to complete API URL. Then I call my fetch function (which is the actual API call). When I call my fetch function I include the url var as an argument.
for (var i = 0; i < userChannels.length; i++) {
var channel = userChannels[i];
var url = 'https://api.twitch.tv/kraken/streams/' + channel + '/?client_id=YOURIDHERE';
//initiate API call
fetch(url);
}
My fetch function is awaiting the url, because I told it to expect something as an argument.
function fetch(url) {
//api call using url goes here
}
When you create a function, if you need some info passed to it for it to work, say so by putting it in the parenthesis. You can add more than one.
For instance -
function fetch(url, channel){
//API call with the url
// console.log(channel + ' has been called')
callAnotherFunctionWithThe(response);
}
for (var i = 0; i < userChannels.length; i++) {
var channel = userChannels[i];
var url = 'https://api.twitch.tv/kraken/streams/' + channel + '/?client_id=YOURIDHERE';
//initiate API call
fetch(url, userChannels[i] );
Well, I had a look because I wasn’t clear at all with that…and your explanations are great - and I thought I’d be ok.
But I’m still having the same problem as before: when I call to get my stream status (offline/ online), my function doesn’t iterate through the array of users.
Is it because I’m calling the second function after the first one?
Any chance you could help with that? I thought it was because I was comparing with “null” but that doesn’t change the fact that it only prints for the last user in the array…