jquery .get不能在ie9中使用google api

hal*_*erd 8 ajax jquery get google-api

我无法弄清楚为什么下面的代码在FF中完美运行但在IE9中却没有.

脚本的作用是,点击一个按钮,它从一个表单中选择一些像街道,邮政编码和城镇的值,构建一个字符串,将其提交给谷歌,并返回该地址的纬度和长度(并将其放入两个表格中的字段)

$("#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());

/* test with an alert - string shows fine in both FF and IE */    
    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();

/* test with an alert - fine in FF not in IE */    
alert(lat + ',' + lng);

               $("#sAddressLatitude").val(lat);

           $("#sAddressLongitude").val(lng);
       });
    });

    return false;
});
Run Code Online (Sandbox Code Playgroud)

在这种情况下,此脚本提交的网址是:= 1363342459585"> http://maps.googleapis.com/maps/api/geocode/xml?address=Servicev%C3%A4gen%207,311%2033,Falkenberg,Sweden&sensor=false& = 1363342459585

我已经尝试将缓存更改为false,使用$ .ajax代替$ .get测试,通过输入一些警报,但我似乎无法进入$ .get函数

我已经尝试按照http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests中的建议更改MIME类型,但这并没有帮助.

任何人的想法?

编辑:甚至尝试使用谷歌的json结果,看看问题是否存在于XML中,但这也不起作用.

$.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);
    }
});
Run Code Online (Sandbox Code Playgroud)

rob*_*lep 6

因为您正在执行跨域请求,所以浏览器需要支持此功能.大多数现代浏览器(如FF和Chrome)都支持它,但IE9仅在满足特定要求时才支持它.

下面是微软不得不说的是,包括如何得到它的工作(设置为微软网页上提到的所有要求一些指针可以得到满足).

  • 嗨罗伯特,谢谢你指点我正确的方向.知道了谷歌的用途,我发现这个http://stackoverflow.com/questions/11487216/cors-with-jquery-and-xdomainrequest-in-ie8-9是什么让我指出了一个有助于解决我的问题的工具.可以在这里下载:https://github.com/Ovea/cors/blob/master/src/main/resources/com/ovea/cors/jquery.ie.cors.js (2认同)