Final
Final
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
<!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>
|
||||
nocache = "&nocache=" + Math.random() * 1000000
|
||||
url = "rss.news.yahoo.com/rss/topstories"
|
||||
out = "";
|
||||
|
||||
request = new asyncRequest()
|
||||
request.open("GET", "xmlget.php?url=" + url + nocache, true)
|
||||
|
||||
request.onreadystatechange = function()
|
||||
{
|
||||
if (this.readyState == 4)
|
||||
{
|
||||
if (this.status == 200)
|
||||
{
|
||||
if (this.responseText != null)
|
||||
{
|
||||
titles = this.responseXML.getElementsByTagName('title')
|
||||
|
||||
for (j = 0 ; j < titles.length ; ++j)
|
||||
{
|
||||
out += titles[j].childNodes[0].nodeValue + '<br>'
|
||||
}
|
||||
document.getElementById('info').innerHTML = out
|
||||
}
|
||||
else alert("Communication error: No data received")
|
||||
}
|
||||
else alert( "Communication error: " + this.statusText)
|
||||
}
|
||||
}
|
||||
|
||||
request.send(null)
|
||||
|
||||
function asyncRequest()
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = new XMLHttpRequest()
|
||||
}
|
||||
catch(e1)
|
||||
{
|
||||
try
|
||||
{
|
||||
request = new ActiveXObject("Msxml2.XMLHTTP")
|
||||
}
|
||||
catch(e2)
|
||||
{
|
||||
try
|
||||
{
|
||||
request = new ActiveXObject("Microsoft.XMLHTTP")
|
||||
}
|
||||
catch(e3)
|
||||
{
|
||||
request = false
|
||||
}
|
||||
}
|
||||
}
|
||||
return request
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user