为什么在IE中不调用回调函数?
-
给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'); }
-
给YouTube打电话:
$.getJSON('https://gdata.youtube.com/feeds/api/users/username/favorites?alt=json', function(data) { alert('called'); })
这两种类型的调用都可以在除 IE 之外的任何其他浏览器上运行。你能解释一下为什么吗?
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。