Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Unable to resolve XML http request

Posted on 2016-09-28
4
98 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…

790 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