jquery - Ajax 和 Places API 获取请求

标签 jquery ajax json google-places-api

我无法向 Google Places API 发送 AJAX 请求。代码:

$.ajax({
    type: 'GET',
    url:'http://maps.googleapis.com/maps/api/place/textsearch/json?',
    dataType: 'json',
    data: {
        'query' : "restaurants+in+" + cityname,
        'key' : MyPublicKey,
        'sensor' : "false"
    },
    success: function(restaurans) {
        console.log(restaurants);
    }
});

我做错了什么?

最佳答案

我猜REST API不能这样使用(我猜原因之一应该是CORS)

参见Google Places API

Looking to use this service in a JavaScript application? Check out the Places Library of the Google Maps API v3.

这应该会引导你

https://developers.google.com/maps/documentation/javascript/places

及其“文本搜索请求”部分提供了 Google 文本搜索服务对象的示例

关于jquery - Ajax 和 Places API 获取请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19975016/

相关文章:

javascript - 如何编写 jQuery 风格的 ng-repeat

java - 使用ajax时如何识别Java Server Faces 2.0复合组件?

jquery - 请推荐一个库来在浏览器中模拟 ajax 请求

java - 具有 Spring MVC 的 Jackson 重复嵌套对象不反序列化

javascript - MVC 在局部 View 中使用 JS

jquery - 解决 CSS 滚动条宽度

jquery - 更新每个 JSON 值的 HTML 值

javascript - 如何让 jQuery .get 返回 JSON 数据?

javascript - 如何监听元素上的 "particular"动画结束?

php - Safari 错误。 JavaScript ajax json 对象 - 无法获取属性。对象可能不再存在