Reputation: 51063
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);
};
Upvotes: 1
Views: 312
Reputation: 51063
I tracked this down to be an extra comma after my ResourceList
array in the JSON. FF handles it , IE not. I was trimming my comma with
jsonReply.Remove(jsonReply.Length - 1, 1);
but that only trimmed the last \n
, because I was using StringBuilder.AppendLine(). Changing the code to
jsonReply.Remove(jsonReply.Length - 3, 3);
solved the problem nicely.
Upvotes: 1