
- 前端(HTML/CSS/JavaScript)sidaotech.com
HTML
html
游戏商城
JavaScript (使用AJAX模拟从后端获取数据) javascript // app.js document.addEventListener('DOMContentLoaded', function() { fetch('/api/games') // 假设后端API地址是/api/games .then(response => response.json()) .then(games => { const gameList = document.getElementById('game-list'); games.forEach(game => { const gameElement = document.createElement('div'); gameElement.textContent = `${game.name} - ${game.price}`; gameList.appendChild(gameElement); }); }) .catch(error => console.error('Error:', error)); }); 2. 后端(Node.js/Express) Node.js (使用Express框架) javascript // server.js const express = require('express'); const app = express(); const port = 3000;
// 假设我们有一个模拟的游戏数据库
const games = [
{ id: 1, name: ‘游戏1’, price: 99.99 },
{ id: 2, name: ‘游戏2’, pri