开发者

Having IE Issues When Passing Object By Ref. and Dynamically Adding Properties

So, I've created a function to do some error checking on an XML file that I recieve from an AJAX call. Part of the validation is that the function then builds out an object for easy access while I process that data into a form. In FF, works like a charm. IE dies with the error:

Object doesn't support开发者_StackOverflow中文版 this property or method

Here is the function (minus the un-important bits):

function checkReceiveXMLTagString( doc, messageObject, tag ) {

    var tag_nodes = doc.getElementsByTagName( tag );

    ...do some error checking...

    messageObject[tag] = tag_str; <-- error occurs on this line

    return true;
}

Here is an example of how the function is call:

if ( checkReceiveXMLTagString( messageObject.Name[0], messageObject.Name[0], "First" ) ) {

    ...process messageObject.Name[0].First...

}

Like I said, FF has no issues. Safari loads the pages as well. IE has issues.

Thanks!


Looks like something is making messageObject be null or undefined


If the error is on this line:

messageObject[tag] = tag_str;

Then, the only two ways I know of that that can cause an error are:

  1. messageObject is not an object that you can set properties on (null or undefined are the most likely ways that would happen)
  2. tag is null or undefined

Since I see that your code calls this function hundreds of times so you can't effectively just break on it, I'd suggest you put in some defensive coding to check for those conditions and output something to the debug console to identify what the state is when the problem occurs. You can even trigger a conditional breakpoint with code like this:

if (!messageObject || !tag) {
    debugger;
}

In the toughest cases, you can put an exception handler around it and break when the exception is thrown:

try {
    messageObject[tag] = tag_str;
} catch(e) {
    debugger;
}

Both of these will allow you to capture the condition in the debugger and examine all your parameters at the time of the error.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜