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:
$.ajax
method instead.response.setContentType("text/javascript; charset=UTF-8");
as suggested here.$.getJSON
: $.ajaxSetup({ cache: false });
then reset it to true just before terminating the call as suggested here.json2.js
just in case.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.
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.