-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptsRegister.js
27 lines (26 loc) · 970 Bytes
/
scriptsRegister.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
const submitPostReq = document.getElementById("submitText")
const inputName = document.getElementById("userLoginInput")
const inputPassword = document.getElementById("userPasswordInput")
const statusMessage = document.getElementById("statusMessageText")
submitPostReq.addEventListener("click", async function () {
let data = {
"username": inputName.value,
"password": inputPassword.value,
}
const response = await fetch("http://localhost:3000/register", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
const dataJSON = await response.json()
if (dataJSON.message == "User Already Exists"){
statusMessage.innerHTML = "User already exists..."
}else{
statusMessage.innerHTML = "Registered Successfully!"
inputName.value = ""
inputPassword.value = ""
}
console.log(dataJSON)
});