Soundcloud API - Origin< mysite> Access-Control-Allow-Origin不允许使用 [英] Soundcloud API - Origin <mysite> is not allowed by Access-Control-Allow-Origin

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

问题描述

作为播放播放列表或后续播放列表的后续行动跟踪永久链接而不是trackid :除了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无法加载 http://api.soundcloud.com/playlists/ .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.

来自 XmlHttpRequest错误:Access-Control-Allow-Origin不允许使用null我怀疑问题与jsonp有关,但实际上这是是我的专业知识。

From XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin I suspect the problem is something to do with jsonp, but really this is out of my expertise.

任何建议表示赞赏。

谢谢,Martin。

推荐答案

您可以尝试使用JSONP方法。这是使用JSONP而不是XMLHttpRequest的更新的小提琴。主要区别在于 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不允许使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆