我正在尝试使用jQuery调用Google Places API1,但似乎因为跨域安全问题而失败。我尝试将这个请求作为一个JSONP请求,它运行了,但是服务器直接返回了JSON,所以在jQuery中解析失败。有人找到解决这个问题的办法了吗?
var requestUrl = "https://maps.googleapis.com/maps/api/place/search/json?location=" +
location.coords.latitude + "," + location.coords.longitude + "&radius=100&types=restaurant&sensor=false&key=<<api key here>>";
// Called with
$.getJSON(requestUrl + "&callback=?", onLocateRestaurants);
// or
$.ajax({
url: requestUrl,
type: 'GET',
dataType: 'jsonp',
crossDomain: true,
callback: 'test',
contentType: 'application/json',
success: onLocateRestaurants2,
error: defaultErrorHandler
});发布于 2011-09-23 05:40:52
@Jeremy:我可以为你发布结束语。
Places API不支持JSON-P。有关更多详细信息,请参阅以下问题(由Ken Browning链接):
https://stackoverflow.com/questions/6878007
复制相似问题