-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathformsubmit.js
More file actions
35 lines (32 loc) · 1.03 KB
/
formsubmit.js
File metadata and controls
35 lines (32 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Replace 'YOUR_API_ENDPOINT' with the actual endpoint of your FormSubmit API
const apiEndpoint = 'https://your-api-endpoint.com/submit';
// Define the data you want to send to the API in JSON format
const formData = {
name: 'FreedomCode',
email: 'freedomcode@gmail.com',
message: 'Hello, FormSubmit API!'
};
// Create a request object with the appropriate method, headers, and body
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json' // Specify the content type as JSON
},
body: JSON.stringify(formData) // Convert the data to JSON format
};
// Make the API request
fetch(apiEndpoint, requestOptions)
.then(response => {
if (!response.ok) {
throw new Error(`API request failed with status ${response.status}`);
}
return response.json(); // Parse the response JSON
})
.then(data => {
// Handle the API response data here
console.log('API Response:', data);
})
.catch(error => {
// Handle errors here
console.error('API Request Error:', error);
});