Aucun en-tête «Access-Control-Allow-Origin» n'est présent sur la demande de publication HTTP Ionic2

C'est mon code complet …

this.http.post(link, data, { headers: headers }) .map(res => res.json()) .subscribe(data => { this.data.response = data._body; }, error => { console.log("Oooops!"); }); 

Après avoir exécuté le code, cette erreur est présente:

 "XMLHttpRequest cannot load https://script.google.com/macros/s/AKfycbzdHHKBmLWJYZtFGlJGOrUwlPIWXor1geEOgcSgvhs/dev. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. The response had HTTP status code 401." 

J'ai cherché sur CORS … mais je ne peux pas m'en prendre en compte …

Toute aide serait appréciée.

J'ai le même problème mais après quelques heures pour rechercher mon problème.

Ionic.config.json

 { "name": "KickStarter", "app_id": "85ff0666", "v2": true, "typescript": true, "proxies": [ { "path": "/mobile", "proxyUrl": "http://xxxxx:port/mobile" } ] } 

Vous devriez utiliser le ionic g provider [name-of-provider] --ts il générera un fournisseur pour faire une demande comme ceci:

 export class AuthProvider { data: any = null; constructor(public http: Http) { } load() { if (this.data) { // already loaded data return Promise.resolve(this.data); } // don't have the data yet return new Promise(resolve => { // We're using Angular Http provider to request the data, // then on the response it'll map the JSON data to a parsed JS object. // Next we process the data and resolve the promise wi new data. this.http.get('/mobile/api/authentication') .map(res => res.json()) .subscribe(data => { // we've got back the raw data, now generate the core schedule data // and save the data for later reference resolve(this.data); }); }); } } 

Rappelez-vous simplement: /mobile/api/authentication -> /mobile partir du path dans ionic.config.json .

Téléchargez l'application Allow-Control-Allow-Origin depuis google chrome. Activez le CORS dans l'application installée et exécutez votre code. Cela permettra temporairement le CORS dans votre navigateur.