36 lines
1019 B
HTML
36 lines
1019 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("POST", "http://127.0.0.1/18/xmlget.php?url=" + url + nocache, true)
|
|
XHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
|
|
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>
|