Advertisement
Guest User

Untitled

a guest
Oct 7th, 2023
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. SCRIPT.JS FILE:
  2.  
  3. document.addEventListener('DOMContentLoaded', function() {
  4. const reminderForm = document.getElementById('reminder-form');
  5.  
  6. reminderForm.addEventListener('submit', function(e) {
  7. e.preventDefault();
  8. const email = document.getElementById('email').value;
  9. const reminderTime = document.getElementById('reminder-time').value;
  10.  
  11. // Create a JavaScript object to hold the data
  12. const data = {
  13. email: email,
  14. 'reminder-time': reminderTime
  15. };
  16.  
  17. // Convert the data object to JSON
  18. const jsonData = JSON.stringify(data);
  19.  
  20. // Send the JSON data to the server using fetch
  21. fetch('/sendReminder', {
  22. method: 'POST',
  23. headers: {
  24. 'Content-Type': 'application/json'
  25. },
  26. body: jsonData
  27. })
  28. .then(response => {
  29. if (!response.ok) {
  30. throw new Error(`Network response was not ok (HTTP status ${response.status})`);
  31. }
  32. return response.json();
  33. })
  34. .then(data => {
  35. // Handle the response from the server
  36. console.log(data); // You can log the response for debugging
  37. // Display a message to the user (e.g., success or error message)
  38. })
  39. .catch(error => {
  40. console.error('Error:', error);
  41. // Handle any errors, including non-JSON responses and network issues
  42. // You can display a user-friendly error message here
  43. });
  44. });
  45. });
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement