Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
Después de enviar ajax, el mensaje se repite.

Cuando ejecuto el envío, aparece un mensaje de alerta tantas veces como lo envíe antes de volver a cargar.

Por ejemplo.

mensaje de éxito del envío de la primera ejecución

no actualizar segunda ejecución enviar dos repeticiones ocurre mensaje de éxito

no actualizar tercera ejecución enviar tres repetición ocurre mensaje de éxito

...

no actualizar n ejecutar enviar n repetir ocurre mensaje de éxito

¿Por qué funciona así? ¿Como puedó resolver esté problema?

Mi código es el siguiente.

 $(document).ready(function() { $('#my_modal').on('show.bs.modal', function(e) { var p_index = $(e.relatedTarget).data('p_index'); $(e.currentTarget).find('input[name="p_index"]').val(p_index); $("button#submit").click(function() { $.ajax({ type: "POST", async: false, url: "../receipt/send.php", data: $('form.send_p_index').serialize(), success: function(data) { alert("success") $("#send_p_index")[0].reset() $("#my_modal").modal('hide'); }, error: function() { alert("Error"); } }); }); }); }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

EQUIVOCADO

 $(document).ready(function() { $('#my_modal').on('show.bs.modal', function(e) { var p_index = $(e.relatedTarget).data('p_index'); $(e.currentTarget).find('input[name="p_index"]').val(p_index); $("button#submit").click(function() { $.ajax({ type: "POST", async: false, url: "../receipt/send.php", data: $('form.send_p_index').serialize(), success: function(data) { alert("success") $("#send_p_index")[0].reset() $("#my_modal").modal('hide'); }, error: function() { alert("Error"); } }); }); }); }

CORRECTO : coloque esto fuera de modal.shown porque cada vez que se muestra el modal, escribirá una función de envío que se repite tanto como se muestra.

 $(document).on('click', 'button#submit', function() { $.ajax({ type: "POST", async: false, url: "../receipt/send.php", data: $('form.send_p_index').serialize(), success: function(data) { alert("success") $("#send_p_index")[0].reset() $("#my_modal").modal('hide'); }, error: function() { alert("Error"); } }); });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!