Spaces:
Running
Running
File size: 1,193 Bytes
3dfd7f6 8296cd1 | 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 | document.getElementById('contact-form').addEventListener('submit', async function(e) {
e.preventDefault(); // Prevent default form submission
// Get form data
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const phone_no = document.getElementById('phone').value;
const message = document.getElementById('message').value;
// Construct the API URL
const apiUrl = `https://pieq-data-api.vercel.app/data?email_id=${encodeURIComponent(email)}&name=${encodeURIComponent(name)}&phone_no=${encodeURIComponent(phone_no)}&message=${encodeURIComponent(message)}`;
try {
// Send GET request to the API
const response = await fetch(apiUrl, {
method: 'GET',
headers: {
'Accept': 'application/json'
}
});
const result = await response.json();
alert("Message Sent Successfully!");
// Display result message
} catch (error) {
console.error('Error:', error);
document.getElementById('result').innerText = "Something went wrong!";
}
// Reset the form
this.reset();
});
|