0
當我在我的Cloudant/NoSQL數據庫中使用HTTP GET時,我目前收到Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.
錯誤。爲GET請求設置標頭 - Angular 2 Observable/Promise
我知道,設置Access-Control-Allow-Origin: *
將允許來自localhost
的GET請求,但是我沒有看到專門用於設置標題的Angular 2的文檔。
async getData(): Promise<IPost[]> {
return this._http.get(this._postUrl)
.toPromise()
.then(this.extractData)
.catch(this.handleError);
}
IPost[]
是執行extractData()
之後將要返回的對象。
任何幫助表示讚賞,謝謝你的時間!
您需要在服務器上設置此標題,而不是在Angular應用程序中。 – cgatian
找到它,隱藏在數據庫的設置中。謝謝! – Nihir