-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.js
39 lines (35 loc) · 1.18 KB
/
user.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
document.getElementById("form").addEventListener("submit",postRequest);
function postRequest(e){
e.preventDefault();
let name = document.getElementById('name').value;
let age = document.getElementById('age').value;
let place = document.getElementById('place').value;
let batchName = document.getElementById('batch').value;
let profession = document.getElementById('profession').value;
if( name.length > 3 && age.length > 0 && place.length > 3) {
fetch('https://fakestoreproducts.herokuapp.com/users',{
method:"POST",
body:JSON.stringify(
{
name: name,
age: age,
place: place,
batch_name: batchName,
profession: profession
}
),
headers: {
"Content-type": "application/json"
}
})
.then(res=>res.json())
.then(json=> {
alert("Successfully Registered”")
window.location.href="index.html"
})
.catch(()=> alert("Registration Failed!!"))
}
else {
alert("Please Enter Full Details")
}
}