javascript - Is there any way to gain access to this JSON feed purely from a browser client? -


i'd create client last.fm. music "station" feed here, in json format: http://www.last.fm/player/station/user/skeftomai/mix.

however, when try access via $.getjson(), get

no 'access-control-allow-origin' header present on requested resource. origin 'http://my.exampledomain.com' therefore not allowed access.

so unfortunately have cors issue on last.fm's end. i'd work around this. here things i've tried:

  1. ajax. fails access-control-allow-origin error.
  2. an iframe document.domain set "www.last.fm" or "last.fm". fails sameorigin iframe error.
  3. jsonp. unfortunately jsonp doesn't seem supported feed.
  4. a <script> tag src pointing feed link. unfortunately $('#scripttagid').html() empty.
  5. flash. unfortunately suffers same cross-origin issue.
  6. java applet. heavy, might not have jvm installed, , might suffer same cross-origin issue.

i'm sure away web proxy whereby client utilizes server-size proxy retrieve feed...but really, want pure client-side app no server-side. i'd host on cdn (s3 + cloudfront).

is there way around this?

no, asking isn't solvable using browser alone. if 3rd party site doesn't support cors or jsonp, you're out of options unless control 3rd party site or can use server of own (or 3rd party proxy such yql) obtain data.

here 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>


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -