开发者

Javascript error in IE [closed]

开发者 https://www.devze.com 2023-04-06 04:32 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasona开发者_JAVA技巧bly answered in its current form.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasona开发者_JAVA技巧bly answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消