jQuery Submitting form Twice jQuery Submitting form Twice php php

jQuery Submitting form Twice


Some times you have to not only prevent the default behauviour for handling the event, but also to prevent executing any downstream chain of event handlers.This can be done by calling event.stopImmediatePropagation() in addition to event.preventDefault().

Example code:

$("#addpayment_submit").on('submit', function(event) {  event.preventDefault();  event.stopImmediatePropagation();});


Also, you're binding the action to the submit button 'click'. But, what if the user presses 'enter' while typing in a text field and triggers the default form action? Your function won't run.

I would change this:

$("#addpayment_submit").click(function(event) {    event.preventDefault();    //code}

to this:

$("#payment").bind('submit', function(event) {    event.preventDefault();    //code}

Now it doesn't matter how the user submits the form, because you're going to capture it no matter what.


Try adding the following lines.

event.preventDefault(); event.stopImmediatePropagation();

This worked for me.