Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 665
  • 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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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