Get JSON file from itunes lookup using javascript

≯℡__Kan透↙ 提交于 2019-12-25 02:37:29

问题


I'm trying to get the info inside the JSON file that itunes lookup returns, but my code doesn't work. If I save file that this url returns, which would be a .js file, and upload it to my server and pass in the url of that file it works, but when I'm trying to read file directly from itunes it doesn't.

Please help me out if you have any clues.

Thanks

<script type="text/javascript">

     $.getJSON( "http://itunes.apple.com/lookup?id=600172326", function(data) {

             var icon = document.getElementById("WallpaperIcon");
             var description = document.getElementById("WallpaperDescription");

             icon.src = data.results[0].artworkUrl100;
             description.innerHTML = data.results[0].description;
      });

</script>

回答1:


iTunes probably doesn't have CORS enabled, so you can't make an Ajax request to the service. However, luckily for you it seems to support JSONP:

$.getJSON('http://itunes.apple.com/lookup?id=600172326&callback=?', ...);

More about $.getJSON and JSONP: http://api.jquery.com/jquery.getjson/#jsonp

DEMO



来源:https://stackoverflow.com/questions/25876331/get-json-file-from-itunes-lookup-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!