I have created the following javascript object dynamically (from PHP):
var t_feed = '';
t_feed += '[';
t_feed += '{name: "Tom Thumb", thumbnail: "images/Tom_Thumb.jpg", link: "http://twitter.com/cnnbrk/statuses/121630545879900161", description: "This is the body of the tweat"},';
t_feed += '{name: "Tom Thumb", thumbnail: "images/Tom_Thumb.jpg", link: "http://twitter.com/cnnbrk/statuses/121622456363524097", description: "This is the body of the tweat"},';
t_feed += '{name: "Tom Thumb", thumbnail: "images/Tom_Thumb.jpg", link: "http://twitter.com/cnnbrk/statuses/121614678341320706", description: "This is the body of the tweat"}';
t_feed += ']';
twitterFeeds[0] = eval(t_feed);
This works fine in IE8+, but I get the following error in IE7:
SCRIPT5007: Unable to get value of the property ‘thumbnail’: object is
null or undefined.
I get this when I try and access the thumbnail property like this:
$.each(twitterFeeds[id], function(i,item){
alert(item.thumbnail);
});
Why does that fail in IE7 and is there a different way of defining a list or object that WILL work?
As a general rule, if you’re using eval() there’s probably something wrong with your design.
You may want to try parsing this string as JSON instead of using eval(), and then work from there.