Working with forms
Submitting Form Data
async function submitForm(formData: FormData) {
const response = await http.fetch('submit-form-url', {
method: 'POST',
body: formData
});
if (!response.ok) {
// Handle errors
}
return await response.json();
}
// Usage
const formElement = document.querySelector('form');
const formData = new FormData(formElement);
submitForm(formData);Uploading a File
Last updated
Was this helpful?