Tuesday 15 April 2014

AngularJS access to Cbssports REST API -



AngularJS access to Cbssports REST API -

i trying create angularjs application cbssports plugin.

they provide restful api.

the next $http request:

$http.get(basepath + 'league/owners?access_token=' + cbssportstokens['access_token'] + '&response_format=json') .success(function(data) { homecoming data; });

that wrapped in mill , used in controller. far can tell getting executed correctly. when @ chrome developer tools can see next error on request console:

options http://api.cbssports.com/fantasy/league/owners?access_token=u2fsdgvkx18hyd0…j9drpo7c-oxqqnxgmh0ej0ixvfpf5dkqwklwspcqghipd6hogv_gz&response_format=json angular.js:8560 (anonymous function) angular.js:8560 sendreq angular.js:8354 $http.serverrequest angular.js:8087 wrappedcallback angular.js:11572 wrappedcallback angular.js:11572 (anonymous function) angular.js:11658 scope.$eval angular.js:12701 scope.$digest angular.js:12513 scope.$apply angular.js:12805 done angular.js:8378 completerequest angular.js:8592 xhr.onreadystatechange xmlhttprequest cannot load http://api.cbssports.com/fantasy/league/owners?access_token=u2fsdgvkx18xbod…oqwvjdvsbpzcovsoikevxkrsydo6dbbie0rgmwtkwhmgputyr_xns&response_format=json. 'access-control-allow-origin' header has value 'https://www.cbssports.com' not equal supplied origin. origin 'http://xx.xx.xx.xx:9001' hence not allowed access. ?access_token=u2fsdgvkx18xbodweofeqys5x4adpghyre22fgljljd_ttkrhlwh4lhwfwvxay95bbawvn4te1foqwvjdvsbp…:1

when click link said couldn't load, takes me new page expected output!! cors shouldn't issue here server.

i have read many different issues cors changing headers. follow how have set up:

$httpprovider.defaults.headers.common['access-control-allow-origin'] = '*'; $httpprovider.defaults.headers.common['access-control-allow-headers'] = 'origin';

any advice appreciated, first post so, please allow me know if more info help.

so didn't work. found sort of workaround.

function _get(url) { homecoming $resource(basepath + url, { access_token: cbssportstokens['access_token'], response_format: 'json', callback: 'json_callback' }, { get: { method: 'jsonp' } }); }

i went ahead , used jsonp request instead of get, cbs server seems happier that.

angularjs rest cors

No comments:

Post a Comment