$ .getJSON在IE中不起作用

9 javascript jquery internet-explorer getjson

我使用以下代码从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);
    });
 });
Run Code Online (Sandbox Code Playgroud)

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

Spo*_*ike 15

$.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); }
});
Run Code Online (Sandbox Code Playgroud)

确保你有cache: false.


更新:

它似乎是主机上的配置问题,其中OP实际上使用了请求URL.使用IE Web浏览器直接访问URL会导致主机中止.除了向主机报告问题之外,您无能为力,例如向主持人的网站管理员发送电子邮件.

  • 上面的东西给我错误的IE像**错误,没有运输** (4认同)