// スレッド作成のハンドラ function submitThread(event) { event.preventDefault() const form = event.target const data = { title: form.title.value, boardId: form.boardId.value } fetch('/api/threads', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => { if (response.ok) { window.location.reload() } else { alert('スレッドの作成に失敗しました') } }) .catch(error => { console.error('Error:', error) alert('エラーが発生しました') }) return false } // 投稿作成のハンドラ function submitPost(event) { event.preventDefault() const form = event.target const threadId = form.getAttribute('data-thread-id') const data = { name: form.name?.value || undefined, email: form.email?.value || undefined, content: form.content.value } fetch(`/api/posts?threadId=${threadId}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => { if (response.ok) { form.content.value = '' window.location.reload() } else { alert('投稿の作成に失敗しました') } }) .catch(error => { console.error('Error:', error) alert('エラーが発生しました') }) return false }