使用javascript从iTunes查找获取JSON文件 [英] Get JSON file from itunes lookup using javascript
问题描述
我正在尝试在itunes查找返回的JSON文件中获取信息,但是我的代码不起作用. 如果我保存该URL返回的文件(该文件将是一个.js文件),然后将其上传到我的服务器并传递该文件的URL,则它可以正常工作,但是当我尝试直接从iTunes读取文件时,却没有
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.
谢谢
<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>
推荐答案
iTunes可能未启用CORS,因此您无法向该服务发出Ajax请求.但是,幸运的是,它似乎支持 JSONP :
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=?', ...);
有关$.getJSON
和JSONP的更多信息: http://api.jquery.com/jquery .getjson/#jsonp
More about $.getJSON
and JSONP: http://api.jquery.com/jquery.getjson/#jsonp
这篇关于使用javascript从iTunes查找获取JSON文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!