问题
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