对于这个项目,我只是学习和练习Angular 2.我没有服务器端,并且正在向barchart ondemand api发出API请求 .
我想知道是否有可能绕过cors问题.我对这一切仍然相当新,所以非常感谢宝贝步骤说明!我正在使用http://localhost:8080.
错误信息:( api键已注释掉)
XMLHttpRequest cannot load http://marketdata.websol.barchart.com/getHistory.json?key=MY_API_KEY&symbol=GOOG&type=daily&startDate=20150311000000. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
StockInformationService:
import {Injectable} from 'angular2/core';
import {Http, Headers} from 'angular2/http';
import {Observable} from 'rxjs/Rx';
@Injectable()
export class StockInformationService {
private apiRoot = "http://marketdata.websol.barchart.com/getHistory.json?key=MY_API_KEY&";
constructor (private _http: Http) {}
getData(symbol: string): Observable<any> {
// Tried adding headers with no luck …Run Code Online (Sandbox Code Playgroud)