///////
Search

로그인 기능 가이드

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <main class="login-email"> <h1 class="main-title login-email-title"> 로그인 </h1> <section class="login-email-container"> <h2 class="ir">이메일, 비밀번호 입력 컨테이너</h2> <form> <div class="input-container"> <label for="">이메일</label> <input type="email" id="email"> </div> <div class="input-container input-container-pw"> <label for="">비밀번호</label> <input type="password" id="pw"> </div> <button id="login-btn" class="init-button l-button disabled-button login-btn" type="button">로그인</button> <button class="join-email-btn" type="button">이메일로 회원가입</a> </form> </section> </main> </body> <script> async function login() { const email = document.querySelector("#email").value const password = document.querySelector("#pw").value const url = "https://mandarin.api.weniv.co.kr"; const reqPath ="/user/login"; const loginData = { "user":{ "email": email, "password": password } } const res = await fetch(url+reqPath,{ method:"POST", headers:{ "Content-type" : "application/json" }, body:JSON.stringify(loginData) }) const json = await res.json() console.log(json,"제이손입니다") } const loginButton = document.querySelector("#login-btn"); loginButton.addEventListener("click", login) </script> </html>
JavaScript
복사