Solved

Unable to resolve XML http request

Posted on 2016-09-28
4
76 Views
Last Modified: 2016-10-12
This is the error

perjs.html:1 XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8….1957362&radius=10000&type=gym&key=AIzaSyCaFrzxzjNiBSWLaZ3_cm753jV5OQbFiDM. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.




This is the code...

<html>
  <head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
  <script>
  $(document).ready(function(){
    $.getJSON('https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=10000&type=gym&key=AIzaSyCaFrzxzjNiBSWLaZ3_cm753jV5OQbFiDM', function(myJSONResult){
      var myAddress = [];
      for (i = 0; i < myJSONResult.results.length; i++) {
        myAddress[i] = myJSONResult.results[i].formatted_address;
        alert(myAddress[i]);
      }
      
    });
  });

  </script>

  </head>
  <body>
  
  </body>
  </html>

Open in new window

0
Comment
Question by:yogesh byahatti
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 41821381
Why don't you make use of the places service?
To bad the places service need an instance of a map, but you don't have to use the map.
Have a look at this fiddle : https://jsfiddle.net/avanhalen/n5s4r3re/

I also updated the fiddle to show the markers on the map : https://jsfiddle.net/avanhalen/n5s4r3re/1/
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 41822030
you should do the request usin a server with PHP.
check this post for example :
https://www.experts-exchange.com/questions/28545160/PHP-variable-question.html
0
 

Author Comment

by:yogesh byahatti
ID: 41830477
Albert Van Halen

Thank you for the help. :)

But I am looking to parse the json data from the Google places api.
Please look at this

URL:https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=10000&type=gym&key=AIzaSyCaFrzxzjNiBSWLaZ3_cm753jV5OQbFiDM


From this URL I want to retrieve Json data
0
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 250 total points
ID: 41830618
Well, you can.
In the example page I gave you I did it by showing markers on the map.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now