-1

How can I use XMLHTTPRequest to retrieve a google map?

I need to demonstrate how AJAX works with XMLHTTPRequest.

I have a key and everything.

There is some sample code here:

http://code.google.com/intl/da-DK/apis/maps/documentation/javascript/tutorial.html#api_key

But I am not sure how to change it.

Hints or guidelines are welcome. No need to post the result.

Do I need to create a proxy because of the same origin policy?

Kenci
  • 4,794
  • 15
  • 64
  • 108
  • 1
    You need to read and understand the Google Maps API. This is not a good way to introduce AJAX. – SLaks Jan 06 '12 at 00:31
  • Do you have any other suggestions of service outside of my own page, to demonstrate XMLHTTPrequest? As this is an examn assignment. – Kenci Jan 06 '12 at 00:33
  • 1
    Use a separate URL on your site – SLaks Jan 06 '12 at 00:35
  • I just need to consume some service on the internet using AJAX and XMLHTTPrequest, preferably not from my own page – Kenci Jan 06 '12 at 00:37

1 Answers1

1

You can't, because Google Maps does not use AJAX/xmlHttpRequest to render content on webpages due to cross-domain restrictions put in place by browsers. Instead, javascript from domains other than the one your page is residing on loads itself onto your page. If you want to do an xmlhttpRequest, you must make a request to the server the page is loaded from.

To get an idea of how this may work, a good read is this artice: What is JSONP all about?

Community
  • 1
  • 1
Evan Siroky
  • 9,040
  • 6
  • 54
  • 73