Mainpage
server์์ ํต์
์ฌ์ฉ์๊ฐ ์ ๋ ฅํ lms ์์ด๋์ ๋น๋ฐ๋ฒํธ๋ฅผ ์๋ฒ์ ๋๊ธฐ๊ณ json์ ํํ๋ก ์๋ต์ ๋ฐ๋๋ค.
๋ฏธ๋ฆฌ ์์ฑํด๋ API์ ๋ฐ๋ผ method๋ post ๋ฐฉ์์ผ๋ก, ์ฌ์ฉ์์ LMS ID์ PW๋ฅผ ์๋ฒ์ request๋ฅผ ๋ณด๋ธ๋ค.
function loginmove() {
fetch("/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
pk_user_id: document.getElementById("username").value,
pk_user_pw: document.getElementById("password").value,
}),
}).then((response => response.json()))
.then(json => {
if (json['status'] == 400) {
๋น๋ฐ๋ฒํธ๊ฐ ํ๋ ธ์ ๋
}else if (json['status'] == 500) {
์๋ฒ ์๋ฌ๊ฐ ๋ฐ์ํ์ ๋
}else if (json['status'] == 200) {
์ฌ์ฉ์์ lms ๋ฐ์ดํฐ๋ฅผ ๋ฐ์์์ ๋
}
}
์ด๋ json์ ํํ๋ก id์ password ๊ฐ์ ์ ์กํ๊ธฐ ๋๋ฌธ์ Content-Type ํค๋๋ฅผ application/json๋ก ์ค์ ํ๊ณ body์์๋ JSON.stringify์ ์ด์ฉํด์ JSON ๋ฌธ์์ด๋ก ๋ณํ์ ํด์ request๋ฅผ ๋ณด๋ด์ผ ํ๋ค.
json ๋ฌธ์์ด๋ก ์๋ต๋ฐ์ response๋ js ๊ฐ์ฒด๋ก ๋ณํํ๊ณ , json์ 'statusโ๊ฐ์ ๋ฐ๋ผ ์ฌ์ฉ์์๊ฒ ์ค๋ฅ๋ฅผ ์๋ฆฌ๋์ง, secondpage๋ก ๋์ด๊ฐ ๋ฏธ์ ์ถ ํญ๋ชฉ์ ๋ณด์ฌ์ฃผ๊ฒ ๋๋ค.
Last updated