weixin_33709364 2015-04-01 18:03 采纳率: 0%
浏览 54

IE8中$ .getJSON的问题

I'm unfortunately required to support IE8 and I'm unable to get even a simple $.getJSON request to work properly.

Here is the code:

url = "http://www.somejson.com/data.json";
$.getJSON(url, function(data) {
    var funds = []; var benchmarks = [];
    funds.push(data.funds); benchmarks.push(data.benchmarks);

    $.each( data.funds, function(key, value) {

        var ticker = key;

        // Monthly:
        var appendToDaily = function(ticker) {
            $.each($("#"+ticker), function(key, value, index) {
                $(this).children("td").filter(":nth-child(1)").html( '<td>'+funds[0][ticker].name+'</td>' );
                $(this).children("td").filter(":nth-child(2)").html( '<td>'+ticker+'</td>' );
                $(this).children("td").filter(":nth-child(3)").html( '<td>'+funds[0][ticker].fund.inception_date+'</td>' );
            });
        };

        appendToDaily(ticker);

    });

});

This code works just fine in Chrome, Firefox, and IE9+.

I've tried a few things to fix this with no success:

  • I've tried to use the $.ajax method instead.
  • Set the header for the JSON data to: response.setContentType("text/javascript; charset=UTF-8"); as suggested here.
  • Added this snippet before the $.getJSON: $.ajaxSetup({ cache: false }); then reset it to true just before terminating the call as suggested here.
  • I've explicitly included json2.js just in case.
  • Reverted to JQuery 1.11.0.min.js just in case.

When I attempt to run this code, I get several errors saying that "fund" and "funds" are undefined. I also notice that absolutely nothing inside the $.getJSON callback function fires; even an alert() is ignored.

I'm kind of at my wit's end here so any suggestions would be greatly appreciated! Thanks in advance.

  • 写回答

1条回答 默认 最新

  • 旧行李 2015-04-01 19:08
    关注

    You might not be getting a successful response if your data is undefined. Try using the following snippet to see if you can isolate the error.

    $.getJSON('http://...')
         .done(function(response) { console.log('complete'); })
         .fail(function(error) { console.log('error'); });
    

    If the console outputs 'error' you can work from there. You can either step-debug or output the error result to the console.

    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料