【发布时间】:2012-12-19 11:34:48
【问题描述】:
我对远程 xml 文件的 .ajax 调用有点问题。在 Safari 而不是 IE 9 中运行良好。这可能是 IE 上的跨域问题,或者我的 XML 解析不好。
/* Last FM Scrobbler - get album XML details */
refreshArtwork('Snow Patrol', 'chasing cars');
function refreshArtwork(artist, track) {
$.ajax({
type: 'POST',
url: 'http://ws.audioscrobbler.com/2.0/',
data: {
method: 'track.getInfo',
api_key: 'c88cc53549*******46f056dc05a745',
artist: artist,
track: track,
//format: 'json'
},
dataType: 'xml', //set to json if above
success: getLastfm
});
}
/* parse album XML from LastFM scrobbler */
function getLastfm(xml) {
lstAlbum = $(xml).find('title').text();
lstAlbumart = $(xml).find('image[size="large"]').text();
lstWiki = $(xml).find('summary').text();
lstURL = $(xml).find('url').eq(0).text();
alert(lstAlbumart);
$(".current").html('<div class="playing"><div class="title">' + '<img src="' + lstAlbumart + '" width="250" height="250" /></div></div>');
}// end of getLastfm() function
//***** remote xml here for reference ******//
http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=c88cc53549*******46f056dc05a745&artist=snow%20patrol&track=chasing%20cars
【问题讨论】:
-
你的问题到底是什么?
-
是的,要么是跨域,要么是选择器中的命名空间有问题。过去我在使用 xml 选择器时遇到过问题。
-
尝试修复 .ajax 调用和 xml 遍历,使其在 IE 中工作。感谢您的建议。
-
无法使用 AJAX 检索 xml 跨域。做一些网络搜索...在 SO 和其他网络资源 en.wikipedia.org/wiki/Same_origin_policy 上有数百篇关于此的帖子
-
很多建议和插件,但没有一个有用...到目前为止
标签: jquery