document.getElementById('registerForm').addEventListener('submit', async function (event) { event.preventDefault(); const form = document.getElementById('registerForm'); const formData = new FormData(form); const response = await fetch('/register', { method: 'POST', body: formData, }); const result = await response.json(); if (response.ok) { document.getElementById('message').innerText = '注册成功!'; document.getElementById('message').style.color = 'green'; } else { document.getElementById('message').innerText = `注册失败: ${result.error}`; document.getElementById('message').style.color = 'red'; } });