rest - AngularJS cross-domain requests using $http service -
i'm trying learn angularjs making simple web app using twitch api (https://github.com/justintv/twitch-api) i'm having trouble performing request since it's cross-domain request. have tried
angular.module('streamplaylisterappservices', []).factory('twitchservice', ['$http', function($http) { return function(usercode){ console.log("usercode inside service is: " + usercode) var authheader = 'oauth' + usercode; return $http({ method: 'get', url: ' https://api.twitch.tv/kraken', cache: false, headers:{ 'accept': 'application/vnd.twitchtv.v3+json', 'authorization': 'oauth ' + usercode } }) }; }]);
but error:
xmlhttprequest cannot load https://api.twitch.tv/kraken. request redirected 'http://www.twitch.tv/kraken', disallowed cross-origin requests require preflight.
i know need using jsonp request how set headers way? can show me example of jsonp request , how set headers did in example above? if can't set headers in jsonp requests, how else set request headers?
make request with:
$http.jsonp('https://api.twitch.tv/kraken/games/top?limit=' + number + '&callback=json_callback')
this return json , wont have problems xmlhttprequest
Comments
Post a Comment