-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
62 lines (54 loc) · 1.58 KB
/
app.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//const x =5
//console.log(x);
const forms = document.querySelectorAll(".signup-form")//para ir a traer a la clase la primera clsase del html
//console.log(forms);
/**Si retorna algo *///fetch lo que hace es lanzar asincrona con fetch
const getTemplate = () => {
return fetch("./template.html")
.then((response) => response.text())
}
const sendEmailToApi = (address, template) => {
fetch(`https://bedu-email-sender-api.herokuapp.com/send?id`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
address: address,
template: template,
}),
})
.then((results) => {
console.log(results.status);
if(results.status == 200){
alert("E-mail send!!!")
} else {
alert("Send failed")
}
document.getElementById("email").value = ""
})
.catch((error) => {
console.error(error);
document.getElementById("email").value = ""
alert("Send failed")
});
};
function sendEmail(miVariable) {
miVariable.preventDefault()
const email = miVariable.target.querySelector("input").value
getTemplate()
.then((template) => {
sendEmailToApi(email, template)
})
.catch((error) => {
console.log(error, "error al obtener el template");
})
}
// const sendEmail = (miVariable)=>{
// e.preventDefault();
// console.log(miVariable);
// }
for (let i = 0; i < forms.length; i++){
//console.log(forms[i]);
forms[i].addEventListener("submit",sendEmail)
}