-1

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.

Community
  • 1
  • 1
Taj
  • 43
  • 1
  • 6
  • Check if Javascript is enabled in IE8 or other security settings that's preventing the script from running -- https://support.microsoft.com/en-us/gp/howtoscript – Tasos Apr 01 '15 at 18:21
  • Hrm, JS seems to be enabled; no issues there. Good thought though, I'm sure it's going to be something small and easily missed like that. -_- – Taj Apr 01 '15 at 18:30
  • Step 1: figure out why it isn't working. Look to your console, even IE8 has one. Know what the problem is before you start trying to blindly "fix" it. – Kevin B Apr 01 '15 at 19:19
  • Is this a JSON request, or is it a jsonp request. – Kevin B Apr 01 '15 at 19:23
  • It's JSON. I have been looking at the console, all it says is "fund is undefined" and "funds is undefined". – Taj Apr 01 '15 at 19:33
  • Try adding `alert(JSON.stringify(data))`. That will tell you what's coming back from the server. You can then check that for the `funds` property you are trying to access. Note that `JSON.stringify` is defined in json2, IIRC. – Heretic Monkey Apr 01 '15 at 20:03

1 Answers1

0

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.

Steve G.
  • 590
  • 5
  • 15
  • `.error` is incorrect, you should be using `.fail`. `.success` and `.error` were deprecated in 1.8 – Kevin B Apr 01 '15 at 19:23
  • Additionally, in the error callback, you should be logging the 2nd and 3rd arguments aswell. the are text status and error message generated by jquery. – Kevin B Apr 01 '15 at 19:24
  • Thanks Kevin B, you're absolutely correct. I've been working on a project that's still on jQuery 1.7 for the past 3 months and 'error' was just on my mind. – Steve G. Apr 01 '15 at 19:50