簡體   English   中英

Angular 2,沒有“訪問控制允許來源”

[英]Angular 2 , No 'Access-Control-Allow-Origin'

我們有angular 2應用程序,我們試圖使用Deezer API,但是當我嘗試向GET請求發送GET請求時,出現了給定的錯誤。 我嘗試了很多解決方案,例如使用jsonp並向.htaccess添加'Access-Control-Allow-Origin':'*',但是它們都沒有幫助。 我已經附上了我正在使用的功能。

XMLHttpRequest無法加載https://api.deezer.com/search/track?q=emin 所請求的資源上沒有“ Access-Control-Allow-Origin”標頭。 因此,不允許訪問來源“ www.example.net”。

searchFromDeezer() {
  let url = 'https://api.deezer.com/search/' + this.search_type + '?q=' + this.search_value + '';
  return this._http.get(url).map(res=>res.json())
}

我如何使用jsonp:

like below.

searchFromDeezer() {
  let url = 'https://api.deezer.com/search/' + this.search_type + '?q=' + this.search_value + '?callback=JSONP_CALLBACK';
  return this._jsonp.get(url).map(res=>res.json())
}

解決了

我試圖使用jsonp但出現錯誤,添加后已解決問題
“&output = jsonp&callback = JSONP_CALLBACK”到我的鏈接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM