简体   繁体   English

在本地主机上的请求资源上不存在“ Access-Control-Allow-Origin”标头

[英]No 'Access-Control-Allow-Origin' header is present on the requested resource on localhost

I'm trying to make a call to the Ebay API but it wont run on my local server. 我正在尝试调用Ebay API,但它不会在我的本地服务器上运行。 I get the following error; 我收到以下错误;

No 'Access-Control-Allow-Origin' header is present on the requested resource. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://localhost:3000 ' is therefore not allowed access. 因此,不允许访问源' http:// localhost:3000 '。

I've read something about JSONP and headers but I don't get it. 我已经阅读了有关JSONP和标头的内容,但我不明白。 Can anyone help me explain? 谁能帮我解释一下?

Code (angular2): 代码(角度2):

@Injectable()
export class PostsService {
    constructor(private http: Http) {
        console.log('PostsService Initialized...')
    }

    getPosts() {
        return this.http.get('http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=XXXXXkeyXXXX&RESPONSE-DATA-FORMAT=JSON&callback=processJSON&REST-PAYLOAD&keywords=shoe&global-id=EBAY-GB')
            .map(res => <Post[]>res.json());
    }
}

The api you are trying to access is made up with JSONP so you need to access via jsonp call. 您尝试访问的api由JSONP组成,因此您需要通过jsonp调用进行访问。 JSONP is something like you add script tag in your html. JSONP就像您在html中添加script标签一样。 And fortunately angular 2 has it's own jsonpmodule you can study it at https://angular.io/docs/ts/latest/api/http/index/JsonpModule-class.html 幸运的是,angular 2具有它自己的jsonpmodule,您可以在https://angular.io/docs/ts/latest/api/http/index/JsonpModule-class.html上进行研究

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Runkit-请求的资源上不存在“ Access-Control-Allow-Origin”标头 - Runkit - No 'Access-Control-Allow-Origin' header is present on the requested resource No 'Access-Control-Allow-Origin' header is present on the requested resource error - No 'Access-Control-Allow-Origin' header is present on the requested resource error 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问来源“ http:// localhost:4200” - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access Phonegap请求的资源上没有“Access-Control-Allow-Origin”标头。 因此不允许原点&#39;null&#39;访问 - Phonegap No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access XMLHttpRequest无法加载[archivo]。 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 起源[dominio] - XMLHttpRequest cannot load [archivo]. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin [dominio] 出现错误无法加载资源:请求的资源上不存在“ Access-Control-Allow-Origin”标头 - getting error Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the requested resource XMLHttpRequest无法加载 <instagram OEMBED URL> 。 请求的资源上不存在“ Access-Control-Allow-Origin”标头 - XMLHttpRequest cannot load <instagram OEMBED URL>. No 'Access-Control-Allow-Origin' header is present on the requested resource 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 AngularJS - No 'Access-Control-Allow-Origin' header is present on the requested resource. AngularJS 使用json和jquery的请求资源错误中不存在“ Access-Control-allow-origin”标头 - No 'Access-control-allow-origin' header is present on the requested resource error with json and jquery “向Jawbone UP API发送请求时,”请求的资源上没有&#39;Access-Control-Allow-Origin&#39;标头“错误 - “No 'Access-Control-Allow-Origin' header is present on the requested resource” error when sending request to Jawbone UP API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM