Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

C#
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);
 };
Posted

1 solution

First, you should debug you JavaScript in IE8 and see the structure of the shiftInfo. Than I presume you'll understand what's wrong.

However the first and may be more important thing to think about is why you perform JSON deserialization in JavaScript on the first place. If you utilize the Microsoft ASP.NET Ajax framework correctly you don't have to do that at all as in the callback method after you called your page method you should have your JavaScript object already deserialized. Since you call deserialize I'd start looking for a problem in the jsonString.

Also from the architectural point of view it seems like the problem starts in your C# code rather than in JavaScript.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900