1

I try to access this URL: http://www.wienerlinien.at/ogd_routing/XML_TRIP_REQUEST2?locationServerActive=1&type_origin=coord&name_origin=16.347026:48.205452:WGS84&type_destination=coord&name_destination=16.353268603044167:48.19936173021695:WGS84

As you can see, opening the URL in the Browser, you get an XML-File. You'll also get an XML-File when opening the URL with Python:

response = requests.request('GET', 'http://www.wienerlinien.at/ogd_routing/XML_TRIP_REQUEST2?locationServerActive=1&type_origin=coord&name_origin=16.347026:48.205452:WGS84&type_destination=coord&name_destination=16.353268603044167:48.19936173021695:WGS84')

However, trying to open the same URL with jQuery, will trigger a cross origin error, specifically this one:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.wienerlinien.at/ogd_routing/XML_TRIP_REQUEST2?locationServerActive=1&type_origin=coord&name_origin=16.347026:48.205452:WGS84&type_destination=coord&name_destination=16.353268603044167:48.19936173021695:WGS84. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

var url = 'http://www.wienerlinien.at/ogd_routing/XML_TRIP_REQUEST2?locationServerActive=1&type_origin=coord&name_origin=16.347026:48.205452:WGS84&type_destination=coord&name_destination=16.353268603044167:48.19936173021695:WGS84'

$.get(url, function(data){
  document.write(data)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

I already tried the latest Versions of jQuery 1, 2 and 3 (hosted by Google) and i tried running the code locally and on the server. Always the same error.

How can I send this missing header that the browser itself when opening the URL is sending and which Python is obviously sending.

There is no way I can change any config on the server (wienerlinien.at) end.

This didn't work either (mainly because the repsonse is XML): jQuery ajax request being block because Cross-Origin

Community
  • 1
  • 1
NitricWare
  • 85
  • 9
  • 1
    `How can I send this missing header` You can't. The point is that JS cannot access the third party domain due to the [Same Origin Policy](http://en.wikipedia.org/wiki/Same-origin_policy) as the recipient domain does not respond with CORS headers in the response. The SOP does not apply to a manual browser based request, nor Python or any other server side language. TL;DR: you can't make this request in JS, you'll need to do it server side instead. – Rory McCrossan Dec 09 '16 at 20:14
  • See also [this question](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource?rq=1) for more in depth information. – Rory McCrossan Dec 09 '16 at 20:17

0 Answers0