From 105391ae13eb64f06b149ef79c7e3fbf04732d3b Mon Sep 17 00:00:00 2001 From: Raymond Yang Date: Mon, 10 Jul 2023 15:36:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5web?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- character/add.html | 19 ++++---- character/index.html | 9 +++- login.html | 105 ++++++++++++++++++++++++------------------- register.html | 2 +- 4 files changed, 76 insertions(+), 59 deletions(-) diff --git a/character/add.html b/character/add.html index 89a3725..fa1d962 100644 --- a/character/add.html +++ b/character/add.html @@ -5,9 +5,10 @@ + 新增角色 - - + - - \ No newline at end of file + function login(username, password) { + // 发送登录请求 + axios + .post("./api/v1/login", { + account: username, + password: password, + }) + .then(function (response) { + var token = response.data.token; // 假设服务器返回一个名为"token"的字段 + + // 将JWT存储到本地(通常是使用localStorage) + localStorage.setItem("jwtToken", token); + + // 登录成功后,进行其他操作(例如重定向到受保护的页面) + window.location.href = "./index.html"; + }) + .catch(function (error) { + const message = error.response.data.message; + alert("登入失敗"); + //console.error('登入失敗:', error); + }); + } + + + diff --git a/register.html b/register.html index 53e4ca4..3195ee0 100644 --- a/register.html +++ b/register.html @@ -29,7 +29,7 @@ }); function register(username, password) { - axios.post('http://127.0.0.1:8080/api/v1/register', { + axios.post('./api/v1/register', { account: username, password: password })