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 })