I have the following code that populates a select element with values from an ajax call, via a Page Method. In FF, the code works perfectly, in IE8 I get the error: ‘ResourceList[…].id’ is null or not an object. What can I look at here?
function readShift(jsonString) {
var shiftInfo = Sys.Serialization.JavaScriptSerializer.deserialize(jsonString);
var listItems = "";
listItems += "<option value='0'>[Unassigned]</option>";
for (var i = 0; i < shiftInfo.ResourceList.length; i++) {
listItems += "<option value='" + shiftInfo.ResourceList[i].id + "'>" + shiftInfo.ResourceList[i].name + "</option>";
}
$("#" + resourceListId).html(listItems);
};
I tracked this down to be an extra comma after my
ResourceListarray in the JSON. FF handles it , IE not. I was trimming my comma withbut that only trimmed the last
\n, because I was using StringBuilder.AppendLine(). Changing the code tosolved the problem nicely.