Reverse geolocation, parsing JSON in IE9?

I’m baffled! I’m coding in HTML5 and getting back the geo coordinates with no problems; I set them as cookies for future reference, then pass them to a reverse geolocation server using $.getJSON in jQuery 1.5.1. I have to parse through the results, but I manage to get the user’s US state location (which is my goal) in Firefox, but not in IE.

The JSON appears to be well-formed, and looks like this:

{"place_id":"3065317","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"356821721","lat":"32.9029017","lon":"-96.5636022","display_name":"Church of the Nazarene, Main Street, Dallas, Texas, 75088, United States of America","address":{"place_of_worship":"Church of the Nazarene","road":"Main Street","city":"Dallas","county":"Dallas","state":"Texas","postcode":"75088","country":"United States of America","country_code":"us"}}

Here’s how I’m parsing it (not elegant I know, and I wouldn’t mind suggestions on improvements!):

    $.getJSON('http://nominatim.openstreetmap.org/reverse?format=json&lat=' + Get_Cookie('Latitude') +'&lon=' + Get_Cookie('Longitude') + '&zoom=18&addressdetails=1',
        function(data) {
            var st;
            $.each(data, function(key,val) {
                if (key == 'address') {
                    $.each(val, function(subkey,subval) {
                        if (subkey == 'state') {
                            st = subval;
                        };
                    });
                }
            });
            Set_Cookie('state',st,true,'/');
        });

Would appreciate any help on this… TIA!

Oh, and it does work on Chrome and Safari. I’m finding the problem on IE9; no doubt it exists in earlier versions as well.

Can you confirm whether IE9 actually gets the state in the st variable, by alerting it on a test page?

I tried the code from your post and it seems to get the state just find in IE9, so either it’s something about my test page, or it’s something else other than retrieving the state.

Thanks for checking Paul! It looks as if IE9 is not even making it to the callback function in getJSON, as my alerts never get fired. See below.

$.getJSON('http://nominatim.openstreetmap.org/reverse?format=json&lat=' + Get_Cookie('Latitude') +'&lon=' + Get_Cookie('Longitude') + '&zoom=18&addressdetails=1',
   function(data) {
                 var st;
                 alert('Hello?');
                 $.each(data, function(key,val) {
                       if (key == 'address') {
                             alert('Address found!');
                             $.each(val, function(subkey,subval) {
                                 if (subkey == 'state') {
                                       alert('State found! ' + subval);
                                       st = subval;
                                 };
                           });
                     }
               });
              $('#details').prepend('Welcome ' + st + ' visitor!');            
              Set_Cookie('state',st,true,'/');
        });

It is likely that Internet Explorer is applying aggressive caching? Here’s a viable solution to that:
http://i.justrealized.com/2008/jquerys-getjson-failing-randomly-in-internet-explorer/

What a hoot–I’ve got that tab open already! :slight_smile: Will peruse the article and give it a go. Thanks again, mucho!