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

259
Views
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
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!