-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
51 lines (46 loc) · 1.68 KB
/
index.html
File metadata and controls
51 lines (46 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html>
<head>
<title>Sign Up Form</title>
<link rel="stylesheet" href="public/css/style.css">
<script>
// This function will run when the page is fully loaded
window.onload = function() {
// Attach event listener to the form
document.querySelector('form').addEventListener('submit', function(event) {
event.preventDefault(); // Prevents the form from submitting the traditional way.
const emailValue = document.querySelector('input[name="email"]').value;
// Make a POST request to the server
fetch('http://localhost:3000/subscribe', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: emailValue
})
})
.then(response => response.text())
.then(data => {
alert(data); // Shows the response from the server.
})
.catch(error => {
console.error('Error:', error);
alert('An error occurred. Check the console for details.');
});
});
};
</script>
</head>
<body>
<div class="container">
<form action="action_page.php">
<h1>SIGN UP FOR OUR DAILY INSIDER</h1>
<input type="email" placeholder="Enter your email" name="email" required>
<button type="submit">Subscribe</button>
</form>
</div>
<style>
</style>
</body>
</html>