angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -



angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -

i'm trying create app retrieve stock name, asking , purchase cost yahoo finance api, using restangular. i'm having problem accessing public api in local application i'm creating when request. url parameters i'm sending:

http://finance.yahoo.com/d/quotes.csv?s=msft+ge&f=nab

using postman, request returns array contains stock name, asking cost , purchase cost of stock. doing request in postman returns desired info without errors.

when request in local, next error:

xmlhttprequest cannot load http://finance.yahoo.com/d/quotes.csv?s=msft+ge&f=nab. no 'access-control-allow-origin' header nowadays on requested resource. origin 'http://localhost' hence not allowed access.

the html code follows:

<html ng-app="app"> <head> <title>restangular</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <script src="//code.angularjs.org/1.2.27/angular-resource.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script> <script src="//cdn.rawgit.com/mgonto/restangular/master/dist/restangular.min.js"></script> </head> <body> <div ng-controller="indexctrl" ng-cloak> <ul> <li ng-repeat="person in people">{{person.name}}</li> </ul> </div>

and js:

var app = angular.module('app', ['restangular']) .config(function(restangularprovider) { restangularprovider.setbaseurl('http://finance.yahoo.com/d'); }); app.controller('indexctrl', function($scope, restangular) { $scope.people = restangular.all('quotes.csv?s=msft+ge&f=nab').getlist(); });

i'm confused error because since public api , postman can access it, i'd assume header nowadays in api server. why error when requesting local?

any help appreciated.

here's me making jsonp request fails because it's trying receive csv file. don't think restangular knows how read csv files either attempting. think need same thing using yql api instead because don't think going work.

anyway here's code:

http://plnkr.co/edit/gokyqzj0dxw86c6am2up?p=preview

the request (which goes through fails due file type):

app.controller('mainctrl', function($scope, $http) { $scope.name = 'world'; $http.jsonp('http://finance.yahoo.com/d/quotes.csv', { params: { callback: 'json_callback', s: 'msft ge', f: 'nab' } }).success(function(response) { console.log(response); }).catch(function(response) { console.log(response); }) });

angularjs cross-domain cors restangular

Comments

Post a Comment

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -