登入頁使用 AJAX 提交帳密:
alert() 提示。location.href。{
"success": true,
"redirectUrl": "/dashboard",
"token": "eyJhbGciOiJIUzI1NiIs...",
"user": { "id": 1, "name": "Admin", "roles": ["ROLE_ADMIN"] }
}
$.ajax({
url: '/login',
type: 'POST',
data: $('#loginForm').serialize(),
dataType: 'json',
success: function(resp) {
if (resp.success) {
// 存入 Cookie 或 localStorage
document.cookie = "token=" + resp.token + "; path=/";
// 攜帶參數跳轉
window.location.href = resp.redirectUrl;
} else {
alert(resp.message); // 失敗提示
}
}
});

