-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
34 lines (30 loc) · 982 Bytes
/
scripts.js
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
const form = document.getElementById('analyze-form');
console.log(form)
form.querySelector('.btn').addEventListener('click', function(event) {
event.preventDefault();
if (!form.user_name.value || !form.user_email.value || !form.fungi_id.value) {
alert('Por favor, preencha todos os campos obrigatórios.');
return;
}
let jsonObject = {
"user_name": form.user_name.value,
"user_email": form.user_email.value,
"fungi_id": form.fungi_id.value
};
fetch('http://127.0.0.1:5000/analyze', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(jsonObject),
})
.then(response => response.json())
.then(data => {
console.log(data);
alert('Formulário enviado com sucesso!');
})
.catch((error) => {
console.error('Error:', error);
alert('Ocorreu um erro ao enviar o formulário.');
});
});