Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

268
Visualizações
How to change page and call function at the same time?

HELP! Event onClick needs to send data to the server and change the page at the same time. Here is my code ,but data is send with method POST ,but page are not changing...

 const commandButton = document.getElementById("order");
  commandButton.onclick = function () {
    createOrder(); // A function that sends users data to server with POST method
    window.location.href = "http://127.0.0.1:5500/front/html/confirmation.html";
  };
  function createOrder() {
    const firstName = document.getElementById("firstName").value;
    const lastName = document.getElementById("lastName").value;
    const address = document.getElementById("address").value;
    const city = document.getElementById("city").value;
    const email = document.getElementById("email").value;
    const newCustomer = {
      // newCustomer is an object which will be changed into string with JSON.stringify
      contact: {
        firstName: firstName,
        lastName: lastName,
        address: address,
        city: city,
        email: email,
      },
      products: panier,
    };
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think the problem is because you haven't prevent form from making it's own general request, try using event.preventDefault(); in onclick handler to prevent form doing it's general operation and check that solves problem or not.

const commandButton = document.getElementById("order");
commandButton.onclick = function (event) {
  event.preventDefault();
  createOrder(); // A function that sends users data to server with POST method
  window.location.href = "http://127.0.0.1:5500/front/html/confirmation.html";
};
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda