Solved

Ajax , Google MAP API directions

Posted on 2013-11-11
5
619 Views
Last Modified: 2013-11-27
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
Comment
Question by:Starquest321
  • 3
  • 2
5 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39641324
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
 

Author Comment

by:Starquest321
ID: 39642370
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
 
LVL 82

Expert Comment

by:leakim971
ID: 39642447
so consider my answer only apply to the second request
0
 

Author Comment

by:Starquest321
ID: 39643653
Hi leak

I am not getting your solution.

Is there anything wrong in coding .
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39644476
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
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…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

828 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