I cannot understand why the next bit of code works fine in FF, but not in IE9.
What the script does is that when the button is clicked, it selects some values, such as street, zip code and city from the form, builds a line, sends it to google and returns the lat and long of this address (and puts it in two fields in form)
$("#google_coordinates").live("click", function(){ var string = encodeURIComponent($('#sAddressStreet1').val())+","; if($('#sAddressStreet2').val() != ""){ string += encodeURIComponent($('#sAddressStreet2').val())+","; } string += encodeURIComponent($('#sAddressPostalcode').val())+","; string += encodeURIComponent($('#sAddressTown').val())+","; string += encodeURIComponent($('#sAddressCountryCode option:selected').text()); alert(string); $.get("http://maps.googleapis.com/maps/api/geocode/xml?address="+string+"&sensor=false", function(xml){ $(xml).find('location').each(function() { lat = $(this).find('lat').text(); lng = $(this).find('lng').text(); alert(lat + ',' + lng); $("#sAddressLatitude").val(lat); $("#sAddressLongitude").val(lng); }); }); return false; });
The URL that this script sends in this case: = 1363342459585 "> http://maps.googleapis.com/maps/api/geocode/xml?address=Servicev%C3%A4gen%207,311%2033, Falkenberg, Sweden & sensor = false & = 1363342459585
I tried changing the cache to false, using $ .ajax instead of $ .get, testing, adding some warnings, but I just can't get into the $ .get function
I tried changing the MIME type, as suggested here http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests , but that did not help.
Any ideas anybody?
EDIT: Even tried with json google result to see if there is a problem in XML, but this also does not work.
$.ajax({ type: "GET", url: "http://maps.googleapis.com/maps/api/geocode/json?address="+string+"&sensor=false", dataType: "json", cache: false, success: function(json){ alert("hiero"); lat = json.results[0].geometry.location.lat; lng = json.results[0].geometry.location.lng; $("#sAddressLatitude").val(lat); $("#sAddressLongitude").val(lng); } });
jquery ajax get google-api
half-a-nerd
source share