Login/signup + making a post
Archived a year ago
A
abdi
Copy Paster!
So i have a website i'm making and want the person to get to register, then login, then make a post. but, on the register, it doesn't work and gives this error in console.
```
POST http://127.0.0.1:5500/register 405 (Method Not Allowed)
(anonymous) @ register.html:74
VM153:1 Uncaught (in promise) SyntaxError: Unexpected end of JSON input```
Here's my register.html with line 74 being highlighted
```<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel="icon" type="image/x-icon" href="/images/share.png">
<link rel="stylesheet" type="text/css" href="login.css" />
<title>Sharewell Register</title>
</head>
<body>
<h1 data-value="SHAREWELL" class="sharewell">SHAREWELL</h1>
<div class="login-box">
<h2>Register</h2>
<form id="registerForm">
<div class="user-box">
<input type="text" id="fullname" required>
<label>Full Name*</label>
</div>
<div class="user-box">
<input type="email" id="email" required>
<label>Email*</label>
</div>
<div class="user-box">
<input type="text" id="username" required>
<label>Username*</label>
</div>
<div class="user-box">
<input type="password" id="password" required>
<label>Password*</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<a type="button" class="btn btn-light register" href="landing.html">Go Home</a>
<script>
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let interval = null;
document.querySelector("h1").onmouseover = event => {
let iteration = 0;
clearInterval(interval);
interval = setInterval(() => {
event.target.innerText = event.target.innerText
.split("")
.map((letter, index) => {
if(index < iteration) {
return event.target.dataset.value[index];
}
return letters[Math.floor(Math.random() * 26)]
})
.join("");
if(iteration >= event.target.dataset.value.length){
clearInterval(interval);
}
iteration += 1 / 3;
}, 30);
}
// Handle form submission
document.getElementById('registerForm').addEventListener('submit', async function(e) {
e.preventDefault();
const fullname = document.getElementById('fullname').value;
const email = document.getElementById('email').value;
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
**LINE 74** const response = await fetch('/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ fullname, email, username, password })
});
const data = await response.json();
if (response.ok) {
alert('Registration successful! Please login.');
window.location.href = 'login.html';
} else {
alert('Registration failed: ' + data.message);
}
});
</script>
</body>
</html>```
Here's also my server.js and my media js (shows similar error messages.)
