I have some code where I'm trying to prevent a form from being submitted multiple times. I found this code on another Stack thread but it doesn't work. Instead it submits the form infinite times and lags the entire server!
$(document).ready(function() {
$('form').submit(function() {
console.log("hi")
if ($(this).valid()) {
$(this).submit(function(){
return false;
});
return true; //Tried with an without
}
});
});
Here is a picture of the output in the console:
This keep submitting the form. I just took a picture at that number.
The thread that I found the code above from is the accepted answer on this question and it has many upvotes.
Note that I have multiple forms per page, and many pages with many forms! A solution to one specific form is not sufficient. I need a global solution. Also I'm using Codeigniter.