I am trying to make an asynchronous request to get some data from my server. This all works perfectly well in Firefox but in Internet Explorer, the callback is being called immediately, before any data is received.
$.ajax({
url: "charts.php",
data: { site: site, start: toDateString(start), end: toDateString(end) },
cache: false,
dataType: "json",
success:
function(data) {
var dataPoints = [];
if(data.length == 0){
$("#error").children("label").eq(0).html("There were no results for the site and range selected.");
if($("#error").css("display") == "none"){
$("#error").toggle();
}
$("#large-loader").toggle();
return false;
}
//add each pair of time/maxcalls to an array
$.each(data, function(i, item){
var minute = item[0];
dataPoints.push({
label: pad(parseInt(minute / 60)) + ":" + pad((minute%60)),
data: [minute, item[1]]
});
});
var options = {
xaxis : {
ticks : 24,
tickSize: 60
},
legend : {
show: true,
margin: 10,
backgroundOpacity: .3
},
grid: {
hoverable: true
}
};
//hide loader, show chart
$("#large-loader").toggle();
$("#chart-container").toggle();
$.plot($("#chart"), [data], options);
}
});
The length property exists for arrays, but not for objects. E.g., in your firebug console, you can type:
Then try it with an array:
In reply to the comments:
You ought to be able to do
$.eachon the empty object without problem. You can keep a counter, e.g.That being said, I’m not sure if this is really your problem (but do check, because it well could be). Have you tried
alertingdatain IE? Sometimes you just have to keep moving alerts around until you find the problem.