【问题标题】:Soundcloud API - Origin <mysite> is not allowed by Access-Control-Allow-OriginSoundcloud API - Access-Control-Allow-Origin 不允许来源 <mysite>
【发布时间】:2013-10-19 03:20:17
【问题描述】:

作为Play playlist or track by permalink not trackid 的后续行动:提供的解决方案似乎在任何地方都可以正常工作,除了 Mac 上的 Safari。

在 Mac 上的 Safari 上,我们看到 XMLHttpRequest 无法加载http://api.soundcloud.com/playlists/.json?client_id=...,Access-Control-Allow-Origin 不允许来源

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

来自XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin 我怀疑这个问题与 jsonp 有关,但实际上这超出了我的专业知识。

任何建议表示赞赏。

谢谢,马丁。

【问题讨论】:

标签: javascript soundcloud


【解决方案1】:

您可以尝试使用 JSONP 方法。这是一个使用 JSONP 而不是 XMLHttpRequest 的updated fiddle。主要区别在于getSoundCloudId() 方法和添加了全局jsonpResponse() 方法。

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

【讨论】:

    猜你喜欢
    • 2013-02-05
    • 2011-10-27
    • 1970-01-01
    • 2014-07-14
    相关资源
    最近更新 更多