Files
lpmj6/18/xmlget.html
RobinNixon eeb4267820 Final
2021-06-19 09:50:12 +01:00

35 lines
970 B
HTML

<!DOCTYPE html>
<html> <!-- xmlget.html -->
<head>
<title>Asynchronous Communication Example</title>
</head>
<body>
<h1>Loading XML data into a DIV</h1>
<div id='info'>This sentence will be replaced</div>
<script>
let out = ''
let nocache = "&nocache=" + Math.random() * 1000000
let url = "rss.news.yahoo.com/rss/topstories"
let XHR = new XMLHttpRequest()
XHR.open("GET", "http://127.0.0.1/18/xmlget.php?url=" + url + nocache, true)
XHR.send()
XHR.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
let titles = this.responseXML.getElementsByTagName('title')
for (let j = 0 ; j < titles.length ; ++j)
{
out += titles[j].childNodes[0].nodeValue + '<br>'
}
document.getElementById('info').innerHTML = out
}
}
</script>
</body>
</html>