No 'Access-Control-Allow-Origin' help

how do i properly set my app to use jsonp

a sample of what i have so far
$.get(twitchBaseUrl + names,{dataType: “jsonp”}).then(function(theStream) {
twitchUserInfo[index] = {};
twitchUserInfo[index].user_stream = (theStream.stream ? true : false);
if (twitchUserInfo[index].user_stream) {
onlineUsers.push(twitchUserInfo[index]);
} else {
offlineUsers.push(twitchUserInfo[index]);
}
completedRequest += 1;
return $.get(theStream._links.channel,{dataType: “jsonp”});
})

Correct me if I’m wrong but I believe the usage in jQuery is

$.getJSON('[url]?callback=?')

Where [url] is the https://api.twitch.tv/kraken/... url.

1 Like

so for example it should be like
'https://api.twitch.tv/kraken/streams/freecodecamp/?callback=?’ ?

Yes, that is correct for JSONP.

1 Like

Kraken supports CORS (Access-Control-Allow-Origin:*) so you don’t need to use JSONP and callbacks.

Ex: http://codepen.io/anon/pen/rOGwQG?editors=001 (Added “lirik” to make sure at least one channel was online.)

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.