- The form is submitted without a page reload by preventing the default form submission behavior.
- We send a POST request to the API using
fetch()
, including the form data as JSON in the request body. - The server's response is displayed on the page.
When working with AJAX, it’s important to handle errors properly. Both XMLHttpRequest
and Fetch API provide mechanisms to catch and handle errors.