0

I am trying to get detailed information (hours of operation, phone number, website...) about an establishment via Google Places API. I am making the following $.ajax() call, but am getting the error Uncaught SyntaxError: Unexpected token : which is pointing to the formatting of the JSON response. The response looks good to me. I am able to see the json data correctly when I manually go to the URL: 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" ]
         },
         ...
      ]
   }
}

What can I do to programmatically get the JSON data correctly?

Jon
  • 8,205
  • 25
  • 87
  • 146
  • The response is JSON, not JSONP. The two are not interchangeable - hence your issue. I assume you've made this change in an attempt to get around CORS issues...? If so, it's not going to work. You'll need to make the request server side. See the duplicate for more information. Alternatively you could use the Google Maps JS SDK. – Rory McCrossan Sep 18 '17 at 14:59
  • You do not have JSONP.... – epascarello Sep 18 '17 at 15:00

0 Answers0