More

Error XMLHttpRequest cannot load openlayers geocode?


I'll make a page for viewing routes with openlayers, postgresql / postgis and pgrouting. The part of the seat is already ok, I'm using OSM data. The image below is to illustrate what I'm doing now: a page where the user enters origin and destination and I'll do the geocode these addresses to play the coordinates in my sql to obetr the route.

And the following error is occurring, I saw several posts on the subject but it is not clear how I can solve.

XMLHttpRequest cannot load http://www.openrouteservice.org/php/OpenLSLUS_Geocode.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. /C:/Desenv/FitTaxi/FitTaxi/index.html:1 Uncaught TypeError: Cannot read property 'documentElement' of null

My javascript code:

HTML code:

Call the map…

     

This is a Cross Domain Issue as you are calling a different domain in your XMLHttpRequest than is used for the data.

I use a simple Proxy on our Server for the XMLHttpRequest from OpenLayers and the Proxy, in turn, forwards the request onto its true destination.

An Example of how to make your own Proxy can be seen here

This is also discussed here