Cannot load Deezer API resources from localhost with the Fetch API

前端 未结 3 1950
灰色年华
灰色年华 2020-12-03 15:57

I\'m trying to access the Deezer API from localhost, but I\'m keep getting the following error:

Fetch API cannot load http://api.deezer.com/search/track/auto         


        
3条回答
  •  旧巷少年郎
    2020-12-03 16:05

    For now, it is impossible to make this request. You can proxy request to API from your own backend or use jsonp. Here is a library with fetch-like syntax https://github.com/camsong/fetch-jsonp. Usage example https://jsfiddle.net/4dmfo0dd/1/

    fetchJsonp('https://api.deezer.com/search/track/autocomplete?limit=1&q=eminem&output=jsonp')
    .then(function(response) {
        return response.json();
      })
      .then(json => console.log(json))
      .catch(function(error) { console.log(error); });
    

提交回复
热议问题