<script>
const searchForm = document.getElementById('search-form');const results = document.getElementById('results');searchForm.addEventListener('submit', (e) => {e.preventDefault();const location = document.getElementById('location').value;const radius = document.getElementById('radius').value;// 发起网络请求以获取酒店数据const xhr = new XMLHttpRequest();xhr.open('GET', `/api/hotels?location=${location}&radius=${radius}`);xhr.onload = () => {if (xhr.status === 200) {const hotels = JSON.parse(xhr.responseText);displayHotels(hotels);} else {console.error('出错了:', xhr.status, xhr.responseText);}};xhr.send();});function displayHotels(hotels) {// 清除所有现有的搜索结果while (results.firstChild) {results.removeChild(results.firstChild);}// 创建新列表项并将其附加到结果列表hotels.forEach((hotel) => {const li = document.createElement('li');li.innerHTML = `${hotel.name} (${hotel.distance} 公里)`;results.appendChild(li);});}
script>
本文由:成都民宿于(2024-11-05)发表了关于
搜索最近的旅馆 (搜索最近的旅馆宾馆)的文章
。如转载请注明出处:http://www.cdcy-mail.com
如果您对此感兴趣,可以通过以下联系方式与我们联系:
成都区销售
重庆区销售
云贵区销售
华南区销售
华北区销售
华东区销售
华为企业邮箱销售热线:400-0828-083