JSFiddle - React, Tailwind, and code Playground
HTML
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
var txt,x,i;
if (window.XMLHttpRequest) //創建 XMLHttpRequest對象
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
/*
1.readyState:
0:尚未讀取
1:讀取中
2:已下載完畢
3:資訊交換中
4:處理完畢
2.Status:即HTTP協定的狀態碼
200 正確無誤
3.responseText:回應內容
4.responseXML:回應內容XML格式
*/
{
xmlDoc=xmlhttp.responseXML;
txt="";
x=xmlDoc.getElementsByTagName("title");
y=xmlDoc.getElementsByTagName("link");
for (i=1;i<x.length;i++)
{
txt=txt + "<a href=\"" + y[i].childNodes[0].nodeValue + "\">" + x[i].childNodes[0].nodeValue + "</a><br />";
}
document.getElementById("myDiv").innerHTML=txt;
}
}
xmlhttp.open("GET","http://tw.news.yahoo.com/rss/life",true);
//向伺服器發送請求的類型 open(method,url,async)
xmlhttp.send();
}
</script>
</head>
<body>
<h2>News</h2>
<div id="myDiv"></div>
<button type="button" onclick="loadXMLDoc()">Life</button>
</body>
</html>