0

Here is my code. I tried each and every possible questions and answers here in @stackoverflow but at the end unable to find out the exact solution. Any help would be really apprecaited.

$(function(){
    $(".trx-location-row #trx-location").focusout(function(){
      var vurl = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJCQDPsq9FlDkRjdvuicUg4eo&key=AIzaSyDBgKVgYEVbQxjkbAQ8DfGplN34L0UVPIw';
      $.ajax({
        type: 'GET',      
        url: vurl,                                                                                   
        dataType: 'jsonp',
        jsonp: false,
        jsonpCallback: "myJsonMethod",
        success: function() { 
          debugger
          console.log('Success!'); 
        },                                  
        error: function() { 
          console.log('Uh Oh!');
       },
      });
    });
})

;

  • The API you're calling doesn't support JSONP, it's sending ordinary JSON. – Barmar Feb 04 '17 at 06:47
  • @Barmar if i use only json then also returns error. what should i do ? –  Feb 04 '17 at 06:48
  • Perform the API call from a server script, not the client. – Barmar Feb 04 '17 at 06:49
  • Notice that the URL contains the API key. If you do this from the client, your users can get your API key. – Barmar Feb 04 '17 at 06:50
  • If i am using json this error comes . XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJW-_T2F1…U&key=AIzaSyDBgKVgYEVbQxjkbAQ8DfGplN34L0UVPIw&sensor=false&callback=result. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. –  Feb 04 '17 at 06:50
  • I understand that. AJAX has a same-domain restriction when run from the client, that's why you have to do it from the server. – Barmar Feb 04 '17 at 06:51
  • There are thousands of questions on SO about that error message, you should have learned the solutions during your searching. – Barmar Feb 04 '17 at 06:52

0 Answers0