Solved

Ajax , Google MAP API directions

Posted on 2013-11-11
5
633 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
[X]
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
  • 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
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 …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

726 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