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

144
Vistas
Using AJAX to display a message on page after HTTP POST request

On form submission I would like to stay on the same page and display a message (either success or failure). The HTTP POST request is handled as follows:

app.post('/insertdb', function(request, response) {
   // insert values from form into database
   response.json({success: true});
});

In the client side .ejs file I then try to use ajax to display the alert (I tried following the example from how to use NodeJS pop up a alert window in browser) as follows:

    <script>
      $.ajax({
        url: "/dbinsert",
        type: "post",
        data: 'testing',
        cache: false,
        success: function(response) {
          if(data['success']) {
            alert("success");
          }
          
        },
        error: function () {
          alert("There has been an error");
        }
      });
    </script>

The issue is that when I press the submit button it takes me off the page and displays: ```{"success":true}`` instead of staying on the same page after the form submission and displaying a popup with the status of the request.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

see here: Prevent redirect after form is submitted

you need to add return false; to the end of your AJAX request :)

about 4 years ago · Juan Pablo Isaza Denunciar
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