[英]Soundcloud API - Origin <mysite> is not allowed by Access-Control-Allow-Origin
As a follow-up to Play playlist or track by permalink not trackid : the solution provided works fine seemingly everywhere except Safari on Mac. 作为Play播放列表或通过永久链接而不是trackid进行跟踪的后续措施 :提供的解决方案在Mac上的Safari以外的所有地方似乎都可以正常工作。
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 在Mac上的Safari上,我们看到XMLHttpRequest无法加载http://api.soundcloud.com/playlists/ .json?client_id = ...,Access-Control-Allow-Origin不允许使用Origin
This is somewhat complicated by the fact that we have embedded the JavaScript into another site (Confluence). 由于我们已经将JavaScript嵌入到另一个站点(Confluence)中,这一点有些复杂。 The standalone fiddle worked fine on Safari.
独立的提琴在Safari上运行良好。
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. 由于XmlHttpRequest错误:Access-Control-Allow-Origin不允许使用Origin null我怀疑问题与jsonp有关,但这确实超出了我的专业知识。
Any advice appreciated. 任何建议表示赞赏。
Thanks, Martin. 谢谢,马丁。
You can try using the JSONP approach. 您可以尝试使用JSONP方法。 Here's an updated fiddle using JSONP instead of XMLHttpRequest.
这是使用JSONP代替XMLHttpRequest的更新小提琴 。 The main difference is in the
getSoundCloudId()
method and the addition of a global jsonpResponse()
method. 主要区别在于
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.