From 65e41ac9f107ac5f656ce66561e487b746eaff66 Mon Sep 17 00:00:00 2001 From: zhengxinonly Date: Fri, 19 Apr 2024 23:07:28 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E4=BF=AE=E6=94=B9=20fetch=20=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E4=B8=BA=20ajax,=E7=BB=9F=E4=B8=80=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/view/index.html | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/templates/view/index.html b/templates/view/index.html index 5af9d0e..0ac93f8 100644 --- a/templates/view/index.html +++ b/templates/view/index.html @@ -136,6 +136,9 @@ location.href = "/view/login.html"; } }, + error: function (error) { + location.href = "/view/login.html"; + }, }); admin.setConfigurationPath("/static/config/pear.config.json"); @@ -143,16 +146,20 @@ admin.render(); admin.logout(function () { - popup.success("注销成功", function () { - fetch("/api/v1/logout") - .then((res) => res.json()) - .then(function (data) { - if (data.code !== 0) { - localStorage.removeItem("access_token"); - localStorage.removeItem("refresh_token"); + $.ajax({ + type: "GET", + url: "/api/v1/logout", + success: function (data) { + console.log(data); + if (data.code === 0) { + localStorage.removeItem("access_token"); + localStorage.removeItem("refresh_token"); + popup.success("注销成功"); + setTimeout(function () { location.href = "/view/login.html"; - } - }); + }, 1000); + } + }, }); // 清空 tabs 缓存