0

为什么IE中没有调用回调函数?

  1. 对 Flickr 的调用:

    $.getJSON("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos",
    {
        api_key: APIKey,    
        photoset_id: photoSetID,
        format: "json",
        per_page: 40,
        nojsoncallback: 1           
    }, displayImages);
    
    function displayImages(data) { alert('called'); }
    
  2. 致电 YouTube:

    $.getJSON('https://gdata.youtube.com/feeds/api/users/username/favorites?alt=json', function(data)
    {
        alert('called');
    })
    

这两种类型的调用都适用于除 IE 之外的任何其他浏览器。你能解释一下为什么吗?

4

1 回答 1

1

jQuery 仅在非 IE<=9 浏览器中支持跨域 ajax。要在 IE 中使用这些 API,您需要使用 JSONp(如果可用)或添加一个jQuery 插件,以添加对 IE 使用的 XDomainRequest api 的支持。

如果可能,请使用 JSONp;XDR 有很多限制 - 有关详细信息,请参阅http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

于 2012-04-10T17:08:11.110 回答