I am using jQuery to post forms through ajax like this:
$(document).on("submit",this.id, function (e) {
// Do stuff
})
This way it takes the ID of the form and uses the ID to handle all the necessary things with the data from the different forms on different pages.
This works prefect with one form on the page. When I have multiple forms (with unique ID's) it fails, does not respond/trigger anymore.
I know I can enter the ID of the form myself and use multiple $(document).on... in my jQuery but I really like the approach I am using now.
Is there a way to solve this?
$('form').on('submit', function(e) {});
? You can filter specific actions you need (the// Do stuff
part) on$(this).prop('id')
– Seidel$('form').on
binds right away when the page is loaded, so if you have dynamically generated content such as rendering elements in React, it will not be caught in this. Using$(document).on
can capture elements rendered after page load. – Brittani