跨域请求不工作SoundCloud在Safari [英] Cross Domain Requests Not Working With SoundCloud in Safari
问题描述
我根本无法在Safari JSON响应,要求SoundCloud的API。
I simply cannot get a json response in Safari, calling SoundCloud's API.
var inputSet={url:setUrl},
clientId={client_id:client_id};
$.getJSON( "https://api.soundcloud.com/resolve.json", $.extend(inputSet, clientId), function( data ) {
console.log(data);
});
这将返回Safari浏览器,但不是在Chrome浏览器的产地访问控制误差。 CORS是不工作的。
This returns an Origin Access-Control error in Safari but not in Chrome. CORS is not working at all.
锯 CORS不工作,实行工作的答案,完全一样的错误,只有Safari浏览器。
Saw CORS not working at all, implemented 'working' answer, exact same error, only Safari.
添加一个回调参数不返回该错误,但返回的Ajax错误
parsererror的SyntaxError {}
我presume是由于反应仍然是JSON而不是JSONP。这并不在任何浏览器中运行。
adding a callback parameter does not return that error, however returns the ajax error
"parsererror" SyntaxError {}
which I presume is due to the response still being json and not jsonp. This does not work in either browser.
由于它代表我不能让这种跨域请求铬工作,即使文档
As it stands I cannot get this cross domain request working in chrome, even though the docs
<一个href="https://developers.soundcloud.com/docs#crossdomain">https://developers.soundcloud.com/docs#crossdomain
说我可以的。
Safari浏览器的网络选项卡:
Safari network tab:
Safari浏览器的响应:
Safari response:
[Error] Failed to load resource: Origin https://seam.li is not allowed by Access-Control-Allow-Origin. (17235000.json, line 0)
[Error] XMLHttpRequest cannot load https://api.soundcloud.com/playlists/17235000.json?client_id=CLIENT_ID. Origin https://seam.li is not allowed by Access-Control-Allow-Origin. (seam.li, line 0)
链接的页面加载罚款的浏览器。
Linked page loads fine in browser.
推荐答案
使用其他URL似乎做工精细。与 /resolve.json
的问题就在于它采用了302重定向到您发送到正确的API URL,它不合拍的Safari。
Using the other URLs seems to work fine. The issue lies with /resolve.json
where it uses a 302 Redirect to send you to the right API URL and it doesn't jive with Safari.
按照SoundCloud API文档:
在解决资源,您可以查找和访问API资源时,你只知道SoundCloud.com URL。
The resolve resource allows you to lookup and access API resources when you only know the SoundCloud.com URL.
如果您不需要此功能,我建议您直接使用URL。这里有一个工作的例子。
If you don't need this functionality I suggest using the URL directly. Here's a working example.
$.getJSON("https://api.soundcloud.com/playlists/17235000.json?client_id=CLIENT_ID",
function( data ) {
console.log(data);
});
这篇关于跨域请求不工作SoundCloud在Safari的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!