Advertisement
CheezPuff

[Web - JS] registration for a student

Jul 7th, 2024 (edited)
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const showName = () => {
  2.     let userInput = document.getElementById("inpt").value;
  3.     fetch(`https://jsonplaceholder.typicode.com/users/${userInput}`)
  4.     .then((res) => res.json())
  5.     .then((data) =>{
  6.         console.log(data.name);
  7.     document.getElementById("details").innerHTML = data.name
  8.    
  9.     }).catch((err)=>{
  10.         console.log(err);
  11.     })
  12. }
  13.  
  14. const sendData = () =>{
  15.     const name = document.getElementById("name").value;
  16.     const age = document.getElementById("age").value;
  17.     const id = document.getElementById("id").value;
  18.     fetch("/sendData",{
  19.         method:"POST",
  20.         headers: {
  21.             "Content-Type": "application/json"
  22.         },
  23.         body:JSON.stringify({
  24.             name,age,id
  25.         })
  26.     }).then( res => res.json()).then(data => {console.log(data);})
  27. }
  28.  
  29. const removeUnder18 = () =>{
  30.     fetch("/removeUnder18",{
  31.         method: "DELETE",
  32.         headers:{
  33.             "Content-Type": "application/json"
  34.         }
  35.     }).then(res=>res.json()).then(data => console.log(data)).catch((err)=>{
  36.         console.log(err);
  37.     })
  38. }
  39.  
  40. const sendAndAlert = () => {
  41.     const userName = document.querySelector('#userName').value;
  42.     const age = document.querySelector('#ageOf').value;
  43.     fetch("/alertDetails",{
  44.         method: "POST",
  45.         headers:{
  46.             "Content-Type": "application/json"
  47.         },
  48.         body:JSON.stringify({
  49.             name:userName,
  50.             age:age
  51.         })
  52.     }).then( res => res.json()).then(data =>{
  53.         alert(data.message)
  54.     })
  55. }
  56.  
  57. let object = {name: "Etian",Price: 50}
  58. localStorage.setItem('myUser',object)
  59.  
  60. // I would appreciate feedback and opinions
  61. // Steam: CheezPuff
  62. // Discord: CheezPuff#7720
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement