(feat): Fixed adding emails to subscribers list
This commit is contained in:
		
							parent
							
								
									715f52d2fd
								
							
						
					
					
						commit
						524d56f747
					
				
					 1 changed files with 20 additions and 13 deletions
				
			
		|  | @ -1,20 +1,27 @@ | ||||||
| document.getElementById("notify-button").addEventListener("click", async () => { | document.getElementById("notify-button").addEventListener("click", async () => { | ||||||
|     const emailInput = document.getElementById("email-input"); |   const emailInput = document.getElementById("email-input"); | ||||||
|     const email = emailInput.value; |   const email = emailInput.value.trim(); | ||||||
| 
 | 
 | ||||||
|     if (email) { |   if (email) { | ||||||
|         const response = await fetch("/subscribe", { |     try { | ||||||
|             method: "POST", |       const response = await fetch("/subscribe", { | ||||||
|             headers: { "Content-Type": "application/json" }, |         method: "POST", | ||||||
|             body: JSON.stringify({ email }), |         headers: { "Content-Type": "application/json" }, | ||||||
|         }); |         body: JSON.stringify({ email }), | ||||||
|  |       }); | ||||||
| 
 | 
 | ||||||
|         const result = await response.json(); |       // Check if response is OK, then parse JSON
 | ||||||
|         alert(result.message || result.error); |       const result = await response.json(); | ||||||
|         emailInput.value = ""; // Clear input field
 |       console.log("Server response:", result); | ||||||
|     } else { |       alert(result.message || result.error); | ||||||
|         alert("Please enter a valid email."); |     } catch (error) { | ||||||
|  |       console.error("Error during subscribe fetch:", error); | ||||||
|  |       alert("There was an error during subscription. Please try again later."); | ||||||
|     } |     } | ||||||
|  |     emailInput.value = ""; // Clear input field
 | ||||||
|  |   } else { | ||||||
|  |     alert("Please enter a valid email."); | ||||||
|  |   } | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| window.addEventListener('scroll', function() { | window.addEventListener('scroll', function() { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Blake Ridgway
						Blake Ridgway