Bokdem
Bokdem

Reputation: 464

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. I get the following error;

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

I've read something about JSONP and headers but I don't get it. Can anyone help me explain?

Code (angular2):

@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());
    }
}

Upvotes: 0

Views: 600

Answers (1)

anshuVersatile
anshuVersatile

Reputation: 2068

The api you are trying to access is made up with JSONP so you need to access via jsonp call. JSONP is something like you add script tag in your html. 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

Upvotes: 1

Related Questions