欢迎来到武汉大学酒店预订系统!我们提供专业的住宿服务,满足您的住宿需求。
javascript
// script.js
const form = document.getElementById("booking-form");
const results = document.getElementById("results");form.addEventListener("submit", (e) => {e.preventDefault();const arrivalDate = document.getElementById("arrival-date").value;const departureDate = document.getElementById("departure-date").value;const numAdults = document.getElementById("num-adults").value;const numChildren = document.getElementById("num-children").value;// 发送数据到服务器端进行搜索const data = {arrivalDate: arrivalDate,departureDate: departureDate,numAdults: numAdults,numChildren: numChildren,};fetch("/search", {method: "POST",headers: {"Content-Type": "application/json",},body: JSON.stringify(data),}).then((response) => response.json()).then((data) => {// 处理搜索结果const rooms = data.rooms;// 清除之前的搜索结果results.innerHTML = "";// 在结果列表中显示每个房间rooms.forEach((room) => {const li = document.createElement("li");li.innerHTML = `
${room.name}
${room.description}
价格: ${room.price} 元/晚
预订
`;results.appendChild(li);});}).catch((error) => {console.error(error);alert("搜索失败,请稍后再试。");});
});