【问题标题】:SyntaxError: missing ; before statement Getting this error when trying to call google place search api语法错误:缺少; before 语句在尝试调用 google place search api 时出现此错误
【发布时间】:2014-08-13 06:37:12
【问题描述】:

当我尝试运行此 ajax 代码以获取 1 公里范围内的所有 ATM 时出现 'SyntaxError: missing ; before statement' 错误。

var url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json";
jQuery.ajax({
    url: url,
    dataType: 'jsonp',
    data: {
        'location': '-33.8670522,151.1957362',
        'radius': 1000,
        'types': 'atm',
        'name': '',
        'sensor': false,
        'key': API_KEY
    },
    success: function(response) {
        alert('success');
    }
});

我搜索了很多文章,但没有找到解决方案。如果我从'jsonp' 中删除'p',则没有响应,因为它是跨域的。我该如何解决这个问题?

【问题讨论】:

  • alert('success') 中缺少分号您是否使用严格模式..?
  • 添加了分号,同样的错误。严格模式?
  • 错误指向哪一行?
  • 它没有显示任何行。当我使用 firebug 进行检查时,我看到我得到了响应,但由于出现此错误而无法进一步移动。
  • 你能提供一个完整的例子吗? jsfiddle?

标签: jquery json google-maps-api-3 google-places-api


【解决方案1】:

代码中没有语法错误,错误来自响应。

places-webservice 不支持 JSONP,您无法通过$.ajax请求此服务

使用 Maps-Javascript-API 的places-library 的方法:https://developers.google.com/maps/documentation/javascript/places#place_search_requests

【讨论】:

  • 感谢 Molle 的参考。您能告诉我如何从响应中删除或禁止“html_attributions”吗? { "html_attributions" : [ "Listings by \u003ca href=\"yellowpages.com.au\"\u003e黄页\u003c/a\u003e" ],
  • 基本上response是一个对象,html_attributions是这个对象的一个​​属性,对象的属性可以通过delete删除。我不会提供进一步的建议,因为当您使用结果时,html_attributions 必须始终存在,请参阅:developers.google.com/places/policies#attribution_requirements
猜你喜欢
  • 2020-12-20
  • 1970-01-01
  • 2012-03-21
  • 1970-01-01
  • 1970-01-01
  • 2022-06-15
  • 2013-07-15
  • 1970-01-01
  • 2012-06-24
相关资源
最近更新 更多