Posting this question again, as the code is completely different this time.
Trying to get flight information in XML format from Avinor (Norwegian aviation authorities). Example of query: http://flydata.avinor.no/XmlFeed.asp?TimeFrom=1&TimeTo=7&airport=OSL&direction=D&lastUpdate=2016-04-04T15:03:00Z
I've made an Ajax GET query in order to parse the xml feed into my html p with id=flights, but with no success. I get this error in Firebug console:
SyntaxError: expected expression, got '<'
Firebug->Net->Headers displays the following:
Response headers
Cache-Control private
Content-Length 28088
Content-Type text/xml; Charset=iso-8859-1
Date Mon, 04 Apr 2016 18:32:07 GMT
Server Microsoft-IIS/7.0
X-Powered-By ASP.NET
Request headers
Accept */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Connection keep-alive
Host flydata.avinor.no
User-Agent Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0
When I go into Firebug->Net->XML, I can see the XML data just fine. Can anyone please help me figure this out?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script>
<button type="button" onclick="loadFlights()">
Get Flights</button>
<p id="flights"></p>
<script>
function loadFlights() {
var url = "http://flydata.avinor.no/XmlFeed.asp?TimeFrom=1&TimeTo=7&airport=OSL&direction=D&lastUpdate=2016-04-04T15:03:00Z";
$.ajax({
url: url,
type: "GET",
dataType: "jsonp",
success: function myFunction(xml) {
var x, i, xmlDoc, txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName("flight_id");
for (i = 0; i< x.length; i++) {
txt += x[i].childNodes[0].nodeValue + "<br>";
}
document.getElementById("flights").innerHTML = txt;
}
});
};
</script>
</body>
</html>