jQuery.getJSON not working properly in IE8 with gdata json-c. Why? [duplicate]

坚强是说给别人听的谎言 提交于 2019-11-26 16:19:17

问题


This question already has an answer here:

  • How to make cross-domain AJAX calls to Google Maps API? 1 answer

Using jQuery:

$.getJSON('http://gdata.youtube.com/feeds/api/videos/b2-5GSjZvW8?v=2&alt=jsonc', function(meta){alert(meta.data.title);});

Firefox and Chrome both work as expected, but IE keeps triggering the error function (when using $.ajax) instead of success. The error status is "0" which doesn't help much.

I've also tried using $.ajax with cache:false to no avail.

Any ideas?


回答1:


I can't tell you if it's an error in jquery or IE, but it looks like the XDomainRequest fails in IE. Add this to the URL:

&callback=?

...so the response will be handled as jsonp.

Edit: It looks like Microsoft's XDOmainRequest is not implemented in jQuery, so you can't run Cross-Domain-Requests in jQuery using IE(except jsonp)



来源:https://stackoverflow.com/questions/6318996/jquery-getjson-not-working-properly-in-ie8-with-gdata-json-c-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!