講者 : UR
時間:2020/9/27
index.html
least.html
popular.html
網頁資料夾
index.html
<!DOCTYPE html>
<html>
<head>
<title>
即時電影資訊
</title>
<script type="text/javascript"></script>
</head>
<body>
<div>
<span>最新</span>
<span>熱門</span>
</div>
<div id="content"></div>
</body>
</html>
latest.html
<ul>
<li>太陽之家</li>
<li>法蒂瑪的奇蹟</li>
<li>電影哆啦A夢:大雄的新恐龍</li>
</ul>
popular.html
<ul>
<li>天能</li>
<li>整容液</li>
<li>電影特務搞飛機</li>
</ul>
function getData(pageName){
var req=new XMLHttpRequest();
req.open("get","http://127.0.0.1:8887/"+pageName);
req.onload = function(){
var content = document.getElementById("content");
content.innerHTML = this.responseText;
};
req.send();
};
<span onclick="getData('latest.html');">最新</span>
<span onclick="getData('popular.html');">熱門</span>
index.html