0

Using F12 in firefox, showed "NS_ERROR_FAILURE:" for html:16 (xml.send();)

According to the opensource website https://data.gov.hk/en-data/dataset/clp-team1-electric-vehicle-charging-location/resource/c9dc4e0f-c618-445b-9c00-7f3d952b1e8a, it said HTTPS request method: GET can be used. Why error shown? Thanks !

<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);
}

gis_oc
  • 49
  • 6

1 Answers1

0

This is a Same Origin policy issue; you can't use XmlHttpRequest to fetch a URL unless it's either served from the same domain/port/protocol or else you use (and the target accepts) cross-origin requests.

Additional details: Same origin Policy and CORS (Cross-origin resource sharing)

Paul
  • 35,689
  • 11
  • 93
  • 122