Google Places API jQuery.ajax()请求因工作url失败

如果我在浏览器标签中粘贴以下url:

https://maps.googleapis.com/maps/api/place/search/json?location=51.5237587%2C-0.1583642&radius=500&types=bar&key=MY_KEY_HERE&sensor=false 

…我从Google Places API获得了预期的JSON响应(MY_KEY_HERE当然替换为实际的密钥,此处和下面的.ajax())。 但是在使用这个jQuery.ajax()构造时:

 $.ajax({ type: 'GET', url: "https://maps.googleapis.com/maps/api/place/search/json", data: {"location" : latlng, "radius" : 500, "types" : "bar", "key" : "MY_KEY_HERE", "sensor" : "false",}, dataType: "json", success: function(data) { var pubResults = data; }, error: function(data) { alert(JSON.stringify(data)); }, complete: function(data) { initialize($.oneapi.latitude, $.oneapi.longitude, pubResults); } }); 

…然后没有到达成功块,而是错误块输出:

 {"readyState":0,"responseText":"","status":0,"statusText":"error"} 

在Firefox 5.01中测试。 Web控制台确认.ajax()正在获取此问题顶部提到的URL。 任何想法为什么jQuery调用该URL会导致错误,但是粘贴到浏览器选项卡中的相同URL会产生预期的JSON?

非常感谢您的时间!

这是一个跨域请求。 浏览器默认阻止来自跨域网站的响应。 你需要使用jsonp作为datatyoe。 只需谷歌相同,你可以看到如何使用jquery API完成它。 堆栈溢出也存在问题。

在相同的原始策略下,server1.example.com提供的网页通常无法连接到server1.example.com以外的服务器或与之通信。 HTML元素是一个例外。 利用元素的开放策略,一些页面使用它们来检索对来自其他来源的动态生成的JSON格式数据进行操作的Javascript代码。 此使用模式称为JSONP。