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

208
Views
bootstrap modal ajax send two time on submit

When I open a modal, then click the submit (to send ajax post request for instance) and if I close the modal, reopen it again and re-submit it send 2 times the request (event with e.preventDefault() )

I don't understand what is wrong

    <div class="modal fade bd-example-modal-lg" id="modalA" tabindex="-1" role="dialog"
    aria-labelledby="modalChangeTypeLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body d-flex justify-content-center">
                <select name="nameA" id="idA" class="form-control" required>
                </select>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="submit" id="btnChangeStatusA" class="btn btn-primary">ChangeA</button>
            </div>
        </div>
    </div>
</div>



   <script>


    $(document).ready(function () {

        $("#btnA").click(function () {
            $("#modalA").modal();

            $("#btnChangeStatusA").click('input', function (f) {
                f.preventDefault()
                alert('ok')
            })

            
        })

    })
</script>

https://jsfiddle.net/e0tah93b/

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

it seems to be stacking the calls when you click on #btnA, try doing this instead:

$(document).ready(function () {

   $("#btnA").click(function () {
      $("#modalA").modal();
   })
   $("#btnChangeStatusA").click('input', function (f) {
      f.preventDefault()
      alert('ok')
   })
})
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!