这是我的全部代码..。
this.http.post(link, data, { headers: headers })
.map(res => res.json())
.subscribe(data => {
this.data.response = data._body;
}, error => {
console.log("Oooops!");
});
运行代码后,出现了此错误:
"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."
我搜索过CORS..。但我不能把头绕着它..。
任何帮助都将不胜感激。
发布于 2016-06-12 14:01:37
我也有同样的问题,但几个小时后,我的问题消失了。
ionic.config.json
{
"name": "KickStarter",
"app_id": "85ff0666",
"v2": true,
"typescript": true,
"proxies": [
{
"path": "/mobile",
"proxyUrl": "http://xxxxx:port/mobile"
}
]
}
您应该使用ionic g provider [name-of-provider] --ts
,它将生成提供者来发出如下请求:
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);
});
});
}
}
请记住:/mobile/api/authentication
-> /mobile
,来自path
in ionic.config.json
。
发布于 2016-06-11 04:36:32
从google下载允许-控制-允许-起源应用程序。在安装的应用程序中启用CORS并执行代码。这将暂时允许您的浏览器中的CORS。
https://stackoverflow.com/questions/37763775
复制