8

我一直在 IE 9 中运行此代码,但没有运气。我查看了所有关于 UTF-8 修复等的帖子,但无济于事。有什么想法吗?

$.get({
    url: 'http://api.flickr.com/services/rest/?api_key={apikey}&method=flickr.collections.getTree&user_id=66970820%40N03&collection_id=66947766-72157631850748939',
    success: function () {
        console.log('success!');
    }
}).done(function () {
    console.log('done');
}).fail(function () {
    console.log('fail')
});

它在 Safari、FF 和 Chrome 中运行良好。将 URL 粘贴到 IE 中时,响应很好。

4

3 回答 3

4

@Iden Gozlan,你的回答听起来不错,但我虚弱的头脑很困惑。

@Erik 和 @charlietfl 你对 JSONP 的建议让我走上了正确的道路。这绝对是一个跨域脚本问题。无法理解为什么 IE 是唯一不允许这样做的。我编辑了我的代码,一切都很好!

$.ajax({
  url: 'http://api.flickr.com/services/rest/?api_key={apikey}&method=flickr.collections.getTree&user_id=66970820%40N03&collection_id=66947766-72157631850748939&jsoncallback=doSomeGreatStuff',
  dataType: "jsonp"
});

function doSomeGreatStuff(response) {
  // do some great stuff with the json response
  console.log( response.collections.collection[0].id );
}

帮助我的资源在这里这里,甚至在这里

于 2012-10-30T15:08:54.867 回答
3

这个jQuery XDomainRequest 插件可以创造奇迹。
我在使用 IE8 和 9 时遇到了 ajax 问题,但在不更改任何代码的情况下简单地包含这个插件就给了我 IE8 和 9 CORS ajax 功能:)

于 2013-09-26T05:44:36.517 回答
1

其已知问题,请阅读这篇文章: 带有 CORS 的 IE9 jQuery AJAX 返回“访问被拒绝”

您应该使用 XMLHttpRequest 原始调用或下载以下插件,它将为您提供这种情况的解决方案:

https://github.com/jaubourg/ajaxHooks/blob/master/src/xdr.js

于 2012-10-29T22:58:45.450 回答