【发布时间】:2011-08-16 17:46:32
【问题描述】:
如果我将以下 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);
}
});
...然后 success 块没有到达,而是 error 块输出:
{"readyState":0,"responseText":"","status":0,"statusText":"error"}
在 Firefox 5.01 中进行测试。 Web 控制台确认 .ajax() 正在获取此问题顶部提到的 URL。任何想法为什么对该 URL 的 jQuery 调用会导致错误,但粘贴到浏览器选项卡中的相同 URL 会导致预期的 JSON?
非常感谢您的宝贵时间!
【问题讨论】: