Solved

Ajax , Google MAP API directions

Posted on 2013-11-11
5
609 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

758 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

21 Experts available now in Live!

Get 1:1 Help Now