實(shí)時(shí)掌握每一場比賽的最新動(dòng)態(tài)。
<script>
(function() {// 定時(shí)刷新比分?jǐn)?shù)據(jù)setInterval(function() {// 使用 AJAX 獲取比分?jǐn)?shù)據(jù)var xhr = new XMLHttpRequest();xhr.open("GET", "api/live-scores.json");xhr.onload = function() {if (xhr.status === 200) {// 解析比分?jǐn)?shù)據(jù)var data = JSON.parse(xhr.responseText);// 更新比分表var tableBody = document.querySelector("tbody");tableBody.innerHTML = "";data.forEach(function(match) {var row = document.createElement("tr");var matchCell = document.createElement("td");matchCell.textContent = match.match;row.appendChild(matchCell);var scoreCell = document.createElement("td");scoreCell.textContent = match.score;row.appendChild(scoreCell);var timeCell = document.createElement("td");timeCell.textContent = match.time;row.appendChild(timeCell);tableBody.appendChild(row);});}};xhr.send();}, 1000);})();
</script>