【问题标题】:read xml.aspx file using javascript使用 javascript 读取 xml.aspx 文件
【发布时间】:2017-09-15 13:50:31
【问题描述】:

在 Firefox 中使用 F12,显示“NS_ERROR_FAILURE:” for html:16 (xml.send();)

根据开源网站https://data.gov.hk/en-data/dataset/clp-team1-electric-vehicle-charging-location/resource/c9dc4e0f-c618-445b-9c00-7f3d952b1e8a,表示可以使用HTTPS请求方法:GET。为什么显示错误?谢谢!

<html>
<head>
<title>Reading XML file</title>
</head>

<body>
<h1>XML file</h1>
<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    alert("I am an alert box!");
    var xml = new XMLHttpRequest();
    xml.open('GET','https://opendata.clp.com.hk/GetChargingSectionXML.aspx?lang=en',false);
    xml.send();
    var xmlData = xml.responseText;
    document.write(xmlData);
}

【问题讨论】:

    标签: javascript html asp.net xml


    【解决方案1】:

    这是同源政策问题;您不能使用 XmlHttpRequest 来获取 URL,除非它是从同一个域/端口/协议提供的,或者您使用(并且目标接受)跨域请求。

    更多详情:Same origin Policy and CORS (Cross-origin resource sharing)

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 1970-01-01
      • 2015-06-12
      • 2014-10-16
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多