2013-02-23 38 views
0

我有以下问题:我想通过ajax从下面的代码中获取googlemaps api v3中的数据。它在Chrome和Firefox中运行良好,但不在IE中运行。我究竟做错了什么?Google地图API v3 getJson不能在IE中工作

var lat; 
$.ajax({ 
url: "url", 
cache: false, 
dataType: "json", 
success: function(data) {  
lat = data.results[0].geometry.location.lat; 
}                         
}); 
+0

请添加您从IE获得的错误消息以及正在发生的版本。 – 2013-02-23 18:28:00

回答

0

以下错误事件添加到您的Ajax调用

success: function(data) { 
    lat = data.results[0].geometry.location.lat; 
    }, 
    error: function(xhr, status, error) { 
    alert(status); 
    } 

,让我们知道您在IE中得到什么错误信息,如果有的话。

编辑 - 听起来你正在尝试做一个跨域请求? 如果是这样,请尝试在您的ajax请求之前设置$.support.cors = true;

提取来源http://api.jquery.com/jQuery.support/

To enable cross-domain requests in environments that do not support cors yet but do allow cross-domain XHR requests (windows gadget, etc), set $.support.cors = true;

EDIT2 - 病患者假设你正在运行IE9,在这种情况下,你需要的jQuery插件在这里找到: https://github.com/jaubourg/ajaxHooks/blob/master/src/xdr.js

也看到因此,对于这个答案更多关于为什么IE9需要插件(与Cors)的详细信息:IE9 jQuery AJAX with CORS returns "Access is denied"

EDIT3 - 下载jQuery.XDomainRequest.js并在您的AJAX调用之前包含它。

+0

感谢您的帮助。我得到的错误是“无运输”。 – user1889382 2013-02-23 19:21:26

+0

我添加了$ .support.cors = true;现在我收到一个新的错误:“拒绝访问”。我真的不明白这一点,它仍然适用于Chrome和FF。 – user1889382 2013-02-23 22:09:35

+0

您是否阅读过我上面发布的链接?你需要发布的插件,使其在IE9中工作。 – 2013-02-25 22:40:37