10

我正在使用以下代码从 JSON 中获取数据。

 $(document).ready(function()
 {
   $.getJSON("http://www.example.com/data.php?id=113&out=json", function(data) {

        $.each(data.issue.page, function(i,item) {
            imagesJSON[i] = item["@attributes"];
        });

       alert(imagesJSON.length);
    });
 });

它适用于 Mozilla、Chrome 和其他浏览器,但不适用于 IE。(不在任何版本中)。

4

2 回答 2

18

$.getJSON在 IE 中缓存结果的趋势。改为使用$.ajax

在您的情况下,相关调用应该是这样的:

// Not really sure if you've forgot to var 
var imagesJSON = [];

$.ajax({
  url: "www.example.com/data.php?id=113&out=json",
  cache: false,
  dataType: "json",
  success: function(data) {
    $.each(data.issue.page, function(i,item) {
        imagesJSON[i] = item["@attributes"];
    });

    alert(imagesJSON.length);
  },
  error: function (request, status, error) { alert(status + ", " + error); }
});

确保你有cache: false.


更新:

OP 实际使用的请求 URL 似乎是主机上的配置问题。使用 IE 网络浏览器直接访问 url 会导致主机中止。您只能将问题报告给主机,例如向主机的网站管理员发送电子邮件。

于 2012-04-25T12:13:33.950 回答
2

我在页面上遇到了同样的错误,我添加了这些行:

<!--[if lte IE 9]>
<script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.0/jquery.xdomainrequest.min.js'></script>
<![endif]-->

它最终对我有用;) IE9 不再出错

这篇文章帮助我对 WebService 的 jQuery 调用返回“无传输”错误

于 2014-01-20T14:57:40.187 回答