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

140
Vistas
I am trying to post my json to the url. and I get error 405 but I can see request payload in chrome developer tools. what am I doing wrong
function addUser(username, email, callback) {
    var xhr = new XMLHttpRequest();
    var response;
    var success = !!Math.round(Math.random());
    console.log(success);
    if (!success) {
      response = JSON.stringify({
        success: success,
        error: "Oups, something went wrong!",
      });
    } else {
      response = JSON.stringify({
        success: success,
        user: {
          username: username,
          email: email,
        },
      });
    }
    console.log(response);
    xhr.open("POST", "/echo/json/", true);

    xhr.onload = function () {
      if (xhr.status === 200) {
        callback(JSON.parse(xhr.responseText));
      }
    };
    xhr.setRequestHeader(
      "Content-type",
      "application/x-www-form-urlencoded"
    );
    xhr.send("json=" + response);
  }

My function to call post method..I am trying to call this function with username and email as inputs which I will be getting from HTML form inputs.

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