регистрация.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const registrationForm = document.getElementById('registrationForm');
  2. registrationForm.addEventListener('submit', (event) => {
  3. event.preventDefault();
  4. const name = document.getElementById('name').value;
  5. const phone = document.getElementById('phone').value;
  6. const email = document.getElementById('email').value;
  7. const code = document.getElementById('code').value;
  8. const password = document.getElementById('password').value;
  9. // Создаем объект XML для записи данных
  10. const xml = `
  11. <user>
  12. <name>${name}</name>
  13. <phone>${phone}</phone>
  14. <email>${email}</email>
  15. <code>${code}</code>
  16. <password>${password}</password>
  17. </user>
  18. `;
  19. // Отправляем XML-данные на сервер
  20. fetch('http://localhost:8000/save_user', {
  21. method: 'POST',
  22. headers: {
  23. 'Content-Type': 'text/xml; charset=utf-8'
  24. },
  25. body: xml
  26. })
  27. .then(response => {
  28. if (!response.ok) {
  29. throw new Error('Ошибка при отправке данных на сервер');
  30. }
  31. return response.text();
  32. })
  33. .then(data => {
  34. console.log('Ответ от сервера:', data);
  35. document.getElementById('successPopup').style.display = 'block';
  36. registrationForm.reset();
  37. })
  38. .catch(error => {
  39. console.error('Ошибка:', error);
  40. });
  41. });
  42. // Функция для закрытия всплывающего окна
  43. function closePopup() {
  44. document.getElementById('successPopup').style.display = 'none';
  45. }