Google Places Ajax返回错误

时间:2017-09-18 14:56:47

标签: javascript jquery ajax google-places-api

我试图通过Google Places API获取有关企业的详细信息(营业时间,电话号码,网站......)。我正在进行以下$.ajax()调用,但是收到的错误Uncaught SyntaxError: Unexpected token :指向了JSON响应的格式。回应对我来说很好。当我手动转到URL时,我能够正确地看到json数据:https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJq_FIY5UKhlQRF3Gj5h89erU&key=AIzaSyBy6GyaGufAa-XdQPkJZA6gGxIv8me31YI

 $.ajax({
    url: 'https://maps.googleapis.com/maps/api/place/details/json',
    data: {
      key: 'AIzaSyBy6GyaGufAa-XdQPkJZA6gGxIv8me31YI',
      placeid: 'ChIJq_FIY5UKhlQRF3Gj5h89erU'
    },
    dataType: 'jsonp',
    success: function(response) {
      console.log('success', response);
    }
  });

// json response
{
   "html_attributions" : [], // Uncaught SyntaxError: Unexpected token:
   "result" : {
      "address_components" : [
         {
            "long_name" : "182",
            "short_name" : "182",
            "types" : [ "subpremise" ]
         },
         {
            "long_name" : "8180",
            "short_name" : "8180",
            "types" : [ "street_number" ]
         },
         ...
      ]
   }
}

如何以编程方式正确获取JSON数据?

0 个答案:

没有答案