function OnSuccessPM(results) {
$("#ChatBox").html("");
for (var i = 0; i < results.length; i++) {
$("#ChatBox").append(results[i].username + " : " + results[i].message + ". <br />");
}
var objDiv = document.getElementById("ChatBox");
objDiv.scrollTop = objDiv.scrollHeight;
return false;
}
MetamorphismApp.ChatService.GetPublicMessages(OnSuccessPM, OnFailurePM);
[WebMethod(EnableSession = true)]
public List<Message> GetPublicMessages()
{
List<Message> getMsgsList = (List<Message>)HttpContext.Current.Application["Messages"];
return getMsgsList;
}
I get the following error in IE:
length is null or not an object.
What is the solution?
Simplest (but not the best, the best would be to fix what is being passed to your OnSuccessPM
function) way would be to check the typeOf
the results
variable to make sure it is an Array and only proceed to the results.length
line if it is.
精彩评论