开发者

'Undefined' is null or not an object

开发者 https://www.devze.com 2022-12-20 01:05 出处:网络
Hey guys having a strange problem basically all is fine in good old ff however ie7 is crying like a little baby and throwing the above error - char: 3, \'Undefined\' is null or not an object .

Hey guys having a strange problem basically all is fine in good old ff however ie7 is crying like a little baby and throwing the above error - char: 3, 'Undefined' is null or not an object .

I am splitting a string into a format I need to compare with another string. Once I have split the string I split it further - example below :

    noteDate = $(xml).find('entry:first published').text();
    // split string to get the date - saved in realDate
    var dateCheck = noteDate.split("T");
    var realDate = dateCheck[0];
    var timeCheck = dateCheck[1]; 
    var lastSplit = timeCheck.substring(0, timeCheck.length-1);
    var fullFeedDT = (realDate + " " + lastSplit); 

IE7 is currently moaning about the forth line however I have a feeling the problem may be with line 3 - due to the fact the error has 3 characters (char: 3).

If anyone can spot a problem p开发者_Go百科lease let me know would be greatly appreciated.

Cheers


Your problem is most probably in the first line:

noteDate = $(xml).find('entry:first published').text();

For some reason, your XML data is not being loaded correctly in IE.


insert alert(timeCheck); before the offending line and i supect you will find that it is undefined.


You could try putting in a check that dateCheck.length is 2. Where is noteDate coming from, and is it always in the format dateTtime (is it in ISO date format?).


Did you make sure "noteDate" does actually contain "T"? The way it looks, "dateCheck[1]" does not contain anything, making "timeCheck" equals "undefined".

You may want to check "timeCheck" for content (via alert or console.log in FF) to investigate.


I would first add an alert for each variable in the script to report its value and type (alert((typeof varInstance)+': "'+varInstance+'"');) to make sure its what you expect in IE. Then id go about debugging accordingly. That said Im going to guess that its as Daniel suggests and is an issue with the xml.


the problem was not with the way I was parsing the xml etc. but more down to the fact that ie was getting back the xml and putting it in a string format - solved the problem after reading this thread http://dev.jquery.com/ticket/3143

and also changing the data type in the ajax request from xml - text.

cheers for everyone who inputted to this thread

0

精彩评论

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