Sending data via AJAX using FormData in JavaScript

You can also send data to a server using FormData:

let formData = new FormData(); formData.set('num1', '1'); formData.set('num2', '2'); let promise = fetch('/handler/', { method: 'POST', body: formData, });

Given an object with data:

let obj = { a: 1, b: 2, c: 3 }

Using a loop, form a formData object from this object and send it to a server using the POST method.