main.js 707 B

123456789101112131415161718192021
  1. document.getElementById('registerForm').addEventListener('submit', async function (event) {
  2. event.preventDefault();
  3. const form = document.getElementById('registerForm');
  4. const formData = new FormData(form);
  5. const response = await fetch('/register', {
  6. method: 'POST',
  7. body: formData,
  8. });
  9. const result = await response.json();
  10. if (response.ok) {
  11. document.getElementById('message').innerText = '注册成功!';
  12. document.getElementById('message').style.color = 'green';
  13. } else {
  14. document.getElementById('message').innerText = `注册失败: ${result.error}`;
  15. document.getElementById('message').style.color = 'red';
  16. }
  17. });