Friday, October 24, 2008

IE7 very picky with Javascript & Json: IE counts null objects.

I just came across with another debugging situation with javascript code in IE7.
IE7 takes in consideration null objects.

For example, below is a JSon array of objects.







var markers = [
{
'abbr': '1',
'latitude':33.029764,
'longitude':-97.090090,
'dealer': {
"companyName": "Armstrong Office Interiors","address1" : "3205 Dwyer St","city" : "Flower Mound","state" : "TX","website": "www.armstrongofficeconcepts.com","phone" : "469-568-6648", "address2": "", "zipCode": "75022" , "fax": "(469) 293-6602" , "email": "jarmstrong@armstrongoffice.com" , "dealerType": 1 , "distance": "3.0" , "showcase": "N" , "locationId": "19830" , "contactName": "Armstrong Office Interiors" , "gsa": "Y"}
,
'wp':'n'
}];










In this case as you can see there is only 1 object.
If you do markers.length, you get a total of 1. And that's correct.

No lets say we add a comma "," to the end of the first object.







var markers = [
{
'abbr': '1',
'latitude':33.029764,
'longitude':-97.090090,
'dealer': {
"companyName": "Armstrong Office Interiors","address1" : "3205 Dwyer St","city" : "Flower Mound","state" : "TX","website": "www.armstrongofficeconcepts.com","phone" : "469-568-6648", "address2": "", "zipCode": "75022" , "fax": "(469) 293-6602" , "email": "jarmstrong@armstrongoffice.com" , "dealerType": 1 , "distance": "3.0" , "showcase": "N" , "locationId": "19830" , "contactName": "Armstrong Office Interiors" , "gsa": "Y"}
,
'wp':'n'
}
, // Added extra comma here.
];









run markers.length again and now you will get a count of 2.
In firefox you will still get a count of 1.

No comments:

Post a Comment