实时比分
赛程预告
球队排名
球员数据
新闻动态
<script>
// 使用 AJAX 从 API 获取数据并更新页面// 实时比分const realTimeScores = document.getElementById("real-time-scores");const getRealTimeScores = () => {
);let html = "";data.forEach((match) => {html += `
${match.date}${match.time}${match.homeTeam}VS${match.awayTeam}
`;});matchSchedule.innerHTML = html;}};xhr.send();};// 球队排名const teamStandings = document.getElementById("team-standings");const getTeamStandings = () => {const xhr = new XMLHttpRequest();xhr.open("GET", "api/team-standings");xhr.onload = () => {if (xhr.status === 200) {const data = JSON.parse(xhr.response);let html = "";html += "
排名 | 球队 | 积分 |
";data.forEach((team) => {html += `${team.rank} | ${team.name} | ${team.points} |
`;});html += "
";teamStandings.innerHTML = html;}};xhr.send();};// 球员数据const playerStats = document.getElementById("player-stats");const getPlayerStats = () => {const xhr = new XMLHttpRequest();xhr.open("GET", "api/player-stats");xhr.onload = () => {if (xhr.status === 200) {const data = JSON.parse(xhr.response);let html = "";html += "
球员 | 进球 | 助攻 |
";data.forEach((player) => {html += `${player.name} | ${player.goals} | ${player.assists} |
`;});html += "
";playerStats.innerHTML = html;}};xhr.send();};// 新闻动态const newsFeed = document.getElementById("news-feed");const getNewsFeed = () => {const xhr = new XMLHttpRequest();xhr.open("GET", "api/news-feed");xhr.onload = () => {if (xhr.status === 200) {const data = JSON.parse(xhr.response);let html = "";data.forEach((article) => {html += `
${article.title}
${article.content}
`;});newsFeed.innerHTML = html;}};xhr.send();};// 初次加载页面时获取数据getRealTimeScores();getMatchSchedule();getTeamStandings();getPlayerStats();getNewsFeed();// 定期刷新数据setInterval(() => {getRealTimeScores();}, 10000);
</script>
相关阅读: 足球比分最新消息 实时掌握赛场动态