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

261
Vistas
Confirm Action inside JS success call - cancel button also submitting form

When a user clicks on submit button, I want to show a confirm dialog with a count of records that would be affected. To get the count, I am calling the related url inside ajax and in success am trying to confirm from user. But, in the confirmation dialog box, when user clicks on cancel also, the form is getting submitted successfully.

$(document).ready(function(){    
        $('form').submit(function(e) {
            // e.preventDefault();
            const a= $(id_a).val();
            const b = $(id_b).val();
            const c = $(id_c).val();
            const d = $(id_d).val()
            $.ajax({  
                type: "GET",  
                url: "/myURL",  
                data: {
                    'csrfmiddlewaretoken':$('input[name=csrfmiddlewaretoken]').val(),
                    'a':a,
                    'b':b,
                    'c':c,
                    'd':d
                },
                success: function (data) {
                    if (confirm(`${data.result} records will get affected. Do you want to continue?`)){
                        $('form#id_save').submit();
                    }
                    else {
                        e.preventDefault()
                }
        });
    })
    })
about 4 years ago · Santiago Gelvez
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