-1

I'd like to create a client for last.fm. My music "station" feed is here, in JSON format: http://www.last.fm/player/station/user/skeftomai/mix.

However, when I try to access this via $.getJSON(), I get

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://my.exampledomain.com' is therefore not allowed access.

So unfortunately we have a CORS issue on last.fm's end. I'd like to work around this. Here are some things I've tried:

  1. AJAX. This fails with the Access-Control-Allow-Origin error.
  2. An iframe with document.domain set to "www.last.fm" or "last.fm". This fails with SAMEORIGIN iframe error.
  3. JSONP. Unfortunately JSONP doesn't seem to be supported with this feed.
  4. A <script> tag with src pointing to the feed link. Unfortunately $('#scriptTagId').html() is empty.
  5. Flash. But unfortunately suffers from the same cross-origin issue.
  6. Java applet. Too heavy, everyone might not have the JVM installed, and it might suffer from the same cross-origin issue.

I'm fairly sure I could get away with a web proxy whereby the client utilizes a server-size proxy to retrieve the feed...but I really, really want this to be a pure client-side app with no server-side. I'd like to host this on a CDN (S3 + Cloudfront).

Is there ANY way around this?

Community
  • 1
  • 1
Chad Johnson
  • 21,215
  • 34
  • 109
  • 207
  • Why am I being down-voted? Is this really a bad question? Or off-topic? I'm just trying to find some way around this, and maybe someone has some crazy idea that could work. – Chad Johnson Oct 02 '15 at 21:17
  • possibly lack of research, but that wouldn't make sense as you've already listed all the possible ways around this. – Kevin B Oct 02 '15 at 21:17
  • Yes, I've done a lot of research and experimentation. I'm coming here as a last resort to make sure I haven't missed anything. – Chad Johnson Oct 02 '15 at 21:18
  • I still don't know why I was down-voted. Clearly I did a lot of research from the post. YQL seems like the only answer, and I didn't know about it until I posted here. A down-vote is uncalled for. – Chad Johnson Jan 06 '16 at 22:35
  • 1
    I wouldn't worry about it. They're likely long gone and are unlikely to have received a notification of your comment. – Kevin B Jan 06 '16 at 22:36

1 Answers1

2

No, what you are asking for isn't solvable using the browser alone. If the 3rd party site doesn't support CORS or JSONP, you're out of options unless you control the 3rd party site or can use a server of your own (or any 3rd party proxy such as YQL) to obtain the data.

Here it is with YQL:

$.getJSON('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D\'http%3A%2F%2Fwww.last.fm%2Fplayer%2Fstation%2Fuser%2Fskeftomai%2Fmix\'&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?', function (response) {
    console.log(response.query.results.json);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Kevin B
  • 94,570
  • 16
  • 163
  • 180
  • This is the kind of answer I was looking for! Thank you! Now I don't have to stand up a server for one tiny script. Awesome. – Chad Johnson Oct 02 '15 at 21:28
  • 1
    If you want to play around with the query or make more, here's the console: [clicky me!](https://developer.yahoo.com/yql/console/?q=select%20*%20from%20json%20where%20url%3D%27http%3A%2F%2Fwww.last.fm%2Fplayer%2Fstation%2Fuser%2Fskeftomai%2Fmix%27&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys) All i had to change was `callback=callback` to `callback=?` when i copied it to javascript. – Kevin B Oct 02 '15 at 21:30
  • I appreciate your help Kevin! – Chad Johnson Oct 02 '15 at 21:39