• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 682
  • Last Modified:

Ajax , Google MAP API directions

This is related to Ajax , Google MAP API directions

http://maps.googleapis.com/maps/api/directions/json?origin=806%2BChurch%2BSt%2CMorrisville%2CNC%2CUSA&destination=RDU%2BAirport%2CNC%2CUSA&sensor=false

When i access above URL in browser getting Json Response.

But when i call from Ajax Response is coming as empty (and some times Reload the page to get source : ). What is the mistake in below cade.

Attaching the Code in Html file.
gmap-live.html
0
Starquest321
Asked:
Starquest321
  • 3
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
you're not allowed to download the json data directly from your page
you need to use a server side proxy to capture the data for you and send it back to your page
0
 
Starquest321Author Commented:
Hi
I am running this page in server only. in the attached doc, ajax request getting response to first request but empty value for second request
0
 
leakim971PluritechnicianCommented:
so consider my answer only apply to the second request
0
 
Starquest321Author Commented:
Hi leak

I am not getting your solution.

Is there anything wrong in coding .
0
 
leakim971PluritechnicianCommented:
yes, you can't download the content from your browser that's why you get nothing
Ajax don't allow you to download data from another server, domain or using a different port

I think you misunderstood the way your current page work saying your javascript run on your server as it's embed in an HTML page
More infos here :
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Same_origin_policy_for_JavaScript

That mean your page CAN'T do an AJAX call to Google API to request data

check back ID: 39641324
this solution always work,
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now