老年人评估系统5

实现登录功能,跳转到对应角色的页面
页面还是沿用之前课程的模版样式

const url = `http://localhost:8080/oldMan/Login/${username}/${password}`;

        // 发送 AJAX 请求
        fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            }
        })
            .then(response => {
                if (!response.ok) {
                    throw new Error('网络请求失败');
                }
                return response.json();
            })
            .then(data => {
                console.log('完整响应数据:', data);
                if (data.code === 1) { // 根据后端实际的成功状态码判断
                    const position = data.data.position;
                    switch (position) {
                        case '监护人':
                            window.location.href = '/guardian.html';
                            break;
                        case '评估员':
                            window.location.href = '/assessor.html';
                            break;
                        default:
                            alert('未知职位,登录失败');
                    }
                } else {
                    alert(data.msg); // 显示登录失败信息
                }
            })
            .catch(error => {
                console.error('登录请求出错:', error);
                alert('登录请求出错,请稍后重试');
            });
posted @ 2025-02-10 16:17  Look_Back  阅读(11)  评论(0)    收藏  举报