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:
- ajax. fails access-control-allow-origin error.
- an iframe document.domain set "www.last.fm" or "last.fm". fails sameorigin iframe error.
- jsonp. unfortunately jsonp doesn't seem supported feed.
- a
<script>
tag src pointing feed link. unfortunately$('#scripttagid').html()
empty. - flash. unfortunately suffers same cross-origin issue.
- 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
Post a Comment