【问题标题】:.ajax won't work in IE [duplicate].ajax 在 IE 中不起作用 [重复]
【发布时间】:2012-12-19 11:34:48
【问题描述】:

可能重复:
IE9 jQuery AJAX with CORS returns “Access is denied”

我对远程 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


【解决方案1】:

检查您的 XML 响应并确保 XML 有效。如果您使用 XML,也不要进行跨域请求。如果进行跨域请求,请使用 数据类型:'JSONP'

【讨论】:

  • XML 正确且格式正确。我已经准备好尝试使用 json,但我是它的初学者。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多