Cross Origin Header缺少jQuery Get Request,但没有使用Python或浏览器

时间:2016-12-09 20:01:22

标签: javascript jquery python ajax cross-domain

我尝试访问此网址: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

如您所见,在浏览器中打开URL,您将获得XML文件。使用Python打开URL时,您还会获得XML文件:

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')

但是,尝试使用jQuery打开相同的URL会触发交叉原因错误,特别是这个错误:

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>
&#13;
&#13;
&#13;

我已经尝试了jQuery 1,2和3的最新版本(由Google托管),我尝试在本地和服务器上运行代码。总是一样的错误。

如何发送打开URL时浏览器本身正在发送的丢失标头以及Python显然发送的内容。

我无法更改服务器(wienerlinien.at)上的任何配置。

这也没有用(主要是因为repsonse是XML):jQuery ajax request being block because Cross-Origin

0 个答案:

没有答案