Skip to content
Advertisement

how to post data using AJAX with validation using bootstrap 5?

How can I post ajax with form validation in bootstrap 5 ?

JavaScript

I have a big problem with this. Can somebody help me?

Advertisement

Answer

The above starter code provided by bootstrap documentation uses the checkValidity() method of JavaScript Constraint Validation API to validate the form.

The HTMLInputElement.checkValidity() method returns a boolean value which indicates validity of the value of the element. If the value is invalid, this method also fires the invalid event on the element.

You can make the ajax request if validation is successful as below,

JavaScript

Here is an example ajax request using JavaScript Fetch API and FormData API

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement