Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross Domain Requests Not Working With SoundCloud in Safari

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

This returns an Origin Access-Control error in Safari but not in Chrome. CORS is not working at all.

Saw CORS not working at all, implemented 'working' answer, exact same error, only Safari.

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

https://developers.soundcloud.com/docs#crossdomain

say I can.

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.

like image 539
Liam Bigelow Avatar asked Jan 09 '14 00:01

Liam Bigelow


1 Answers

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.

According to the SoundCloud API Doc:

The resolve resource allows you to lookup and access API resources when you only know the SoundCloud.com 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);
});
like image 128
J.P. Armstrong Avatar answered Sep 28 '22 06:09

J.P. Armstrong