forked from Alipakkr/Voyawander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.js
51 lines (44 loc) · 1.26 KB
/
signup.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
let userUrl=`https://quasarapi.onrender.com/users`;
let firstNameInput=document.getElementById("firstName");
let lastNameInput=document.getElementById("lastName");
let emainInput=document.getElementById("email");
let passwordInput=document.getElementById("password");
let submitButton=document.getElementById("submitRegister");
async function fetchUserData(url){
try{
let res=await fetch(`${url}`);
let data= await res.json();
console.log(data);
}
catch(error){
console.log(error);
}
}
fetchUserData(userUrl);
async function postData(url){
try{
const newUserData={
firstname:firstNameInput.value,
lastname:lastNameInput.value,
email:emainInput.value,
password:passwordInput.value,
}
let res=await fetch(url,{
method:"POST",
headers:{
"Content-type":"application/json",
},
body:JSON.stringify(newUserData),
})
// const updateData=await res.json();
fetchUserData(userUrl);
}
catch(error){
console.log(error);
}
}
submitButton.addEventListener("click",(e)=>{
e.preventDefault();
postData(userUrl);
alert("Signup successfull");
})