-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
52 lines (52 loc) · 1.77 KB
/
Copy pathindex.html
File metadata and controls
52 lines (52 loc) · 1.77 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
52
<!DOCTYPE html>
<html>
<head>
<title>Social Media Account Creation</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Create Your Account</h1>
<form id="create-account-form">
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br>
<button type="submit">Create Account</button>
</form>
<div id="message"></div>
<script>
const form = document.getElementById("create-account-form");
const message = document.getElementById("message");
form.addEventListener("submit", async (event) => {
event.preventDefault(); // Prevent the default form submission
const formData = new FormData(form);
const data = {
username: formData.get("username"),
email: formData.get("email"),
password: formData.get("password")
};
try {
const response = await fetch("http://localhost:3000/create-account", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
});
if (response.ok) {
const json = await response.json();
message.textContent = json.message;
} else {
throw new Error("Server responded with " + response.status);
}
} catch (error) {
console.error(error);
message.textContent = "Error: " + error.message;
}
});
</script>
</body>
</html>