本文介绍了Soundcloud API - Origin< mysite> Access-Control-Allow-Origin不允许使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为:除了Mac上的Safari之外,所提供的解决方案似乎无处不在。

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

在Mac上的Safari上,我们看到
XMLHttpRequest无法加载 .json?client_id = ...,Access-Control-Allow-Origin不允许原点

On the Safari on Mac we see XMLHttpRequest cannot load http://api.soundcloud.com/playlists/.json?client_id=..., Origin is not allowed by Access-Control-Allow-Origin

由于我们已将JavaScript嵌入到另一个站点(Confluence),这有点复杂。独立小提琴在Safari上运行良好。

This is somewhat complicated by the fact that we have embedded the JavaScript into another site (Confluence). The standalone fiddle worked fine on Safari.

来自。主要区别在于 getSoundCloudId()方法以及添加全局 jsonpResponse()方法。

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;
}

这篇关于Soundcloud API - Origin< mysite> Access-Control-Allow-Origin不允许使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 09:10