105 lines
4.0 KiB
HTML
105 lines
4.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ja">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>ゼッケン番号テスト</title>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; margin: 20px; }
|
|
.debug { background: #f0f0f0; padding: 10px; margin: 10px 0; }
|
|
select { padding: 5px; margin: 5px; width: 200px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>ゼッケン番号API テスト</h1>
|
|
|
|
<div>
|
|
<label>イベント選択:</label>
|
|
<select id="eventSelect">
|
|
<option value="">イベントを選択</option>
|
|
<option value="下呂">下呂</option>
|
|
<option value="郡上">郡上</option>
|
|
<option value="美濃加茂">美濃加茂</option>
|
|
<option value="FC岐阜">FC岐阜</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div>
|
|
<label>ゼッケン番号:</label>
|
|
<select id="zekkenSelect">
|
|
<option value="">まずイベントを選択してください</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="debug" id="debug"></div>
|
|
|
|
<script>
|
|
const API_BASE_URL = '/api';
|
|
|
|
function log(message) {
|
|
const debugDiv = document.getElementById('debug');
|
|
debugDiv.innerHTML += new Date().toLocaleTimeString() + ': ' + message + '<br>';
|
|
console.log(message);
|
|
}
|
|
|
|
function loadZekkenNumbers(eventCode) {
|
|
log('loadZekkenNumbers called with eventCode: ' + eventCode);
|
|
|
|
if (!eventCode) {
|
|
log('Event code is empty');
|
|
return;
|
|
}
|
|
|
|
const apiUrl = `${API_BASE_URL}/zekken_numbers/${eventCode}`;
|
|
log('Fetching from URL: ' + apiUrl);
|
|
|
|
fetch(apiUrl)
|
|
.then(response => {
|
|
log('API Response status: ' + response.status);
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
log('API Response data: ' + JSON.stringify(data));
|
|
const select = document.getElementById('zekkenSelect');
|
|
select.innerHTML = '<option value="">ゼッケン番号を選択</option>';
|
|
|
|
if (Array.isArray(data) && data.length > 0) {
|
|
data.forEach(number => {
|
|
const option = document.createElement('option');
|
|
option.value = number;
|
|
option.textContent = number;
|
|
select.appendChild(option);
|
|
});
|
|
log(`Added ${data.length} zekken numbers to select`);
|
|
} else {
|
|
log('No zekken numbers found for this event');
|
|
const option = document.createElement('option');
|
|
option.value = '';
|
|
option.textContent = 'このイベントにはゼッケン番号がありません';
|
|
select.appendChild(option);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
log('Error loading zekken numbers: ' + error.message);
|
|
const select = document.getElementById('zekkenSelect');
|
|
select.innerHTML = '<option value="">エラー: ' + error.message + '</option>';
|
|
});
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
log('DOM Content Loaded');
|
|
log('API_BASE_URL: ' + API_BASE_URL);
|
|
|
|
const eventSelect = document.getElementById('eventSelect');
|
|
eventSelect.addEventListener('change', function(e) {
|
|
log('Event changed to: ' + e.target.value);
|
|
loadZekkenNumbers(e.target.value);
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|