Soundcloud API - Origin is not allowed by Access-Control-Allow-Origin

后端 未结 1 500
陌清茗
陌清茗 2021-01-25 05:57

As a follow-up to Play playlist or track by permalink not trackid: the solution provided works fine seemingly everywhere except Safari on Mac.

On the Safari on Mac we s

相关标签:
1条回答
  • 2021-01-25 06:40

    You can try using the JSONP approach. Here's an updated fiddle using JSONP instead of XMLHttpRequest. The main difference is in the getSoundCloudId() method and the addition of a global jsonpResponse() method.

    function getSoundCloudId(permalink) {
      var jsonp   = document.createElement('script');
      var script  = document.getElementsByTagName('script')[0];
      jsonp.type  = 'text/javascript';
      jsonp.async = true;
      jsonp.src   = 'http://api.soundcloud.com/resolve.json?client_id='+CLIENT_ID 
                  + '&url='+permalink+'&callback=jsonpResponse';
      script.parentNode.insertBefore(jsonp, script);
      return false;
    }
    
    0 讨论(0)
提交回复
热议问题