Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

248
Vistas
405 Error on Fetch to send Data from front to back

I am working on a registration form in HTML. The form uses script to take the data entered by user, and turn it into JSON format so that my backend can process it. My text editor is Visual Studio Code and I am checking the functionality of my code with Five Server extension. When I run the code, I get a 405 (method not allowed) message whenever I try to submit data. I suspect that when I make the fetch call, I am not properly referencing the resource. Does my JavaScript file need to be in the same folder as my HTML file? Or is my issue something else?

 <script>
        const form = document.getElementById('createAccount')
        form.addEventListener('submit', registerUser)
        // Will send Data as JSON
        async function registerUser(event) {
            event.preventDefault()
            const firstName = document.getElementById('signupFname').value
            const lastName  = document.getElementById('signupLname').value
            const email     = document.getElementById('signupEmail').value
            const username  = document.getElementById('signupUsername').value
            const password  = document.getElementById('signupPword').value
            
            //Is this right?
            const result = await fetch('/signup', {
                method: 'POST',
                headers: {
                    'Content-Type':'application/json'
                },
                body: JSON.stringify({
                    firstName,
                    lastName,
                    email,
                    password,
                    username

                })
            }).then((res) => res.json())

            console.log(result)
        }
    </script>

Here is my Javascript

const express = require("express");
const router = express.Router();
const path = require('path');
router.use('/', express.static(path.join(__dirname, 'static')));

// mongodb user model
const User = require("./../models/users");

// Password handler
const bcrypt = require("bcryptjs");

// Signup
router.post("/signup", (req, res) => {
  let { fname, lname, username, password, email } = req.body;
  fname    = fname.trim();
  lname    = lname.trim();
  username = username.trim();
  password = password.trim();
  email    = email.trim();

  if()
// Trimmed code for sake of space
)};
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda