登录令牌过期,重新登录后返回当前页面

 登录页面

$(function() {
            //当前页面进入注册页面,当登录成功返回当前页面
            var para = window.location.search;
            if(para != '') {
                var index = para.indexOf('&path');
                var subPara = para.substring(0, index);
                var path = GetQueryString('path') + subPara;
            }
            $('.log-btn').click(function() {
                $.ajax({
                    type: 'POST',
                    url: reqUrl("student_login"),
                    data: {
                        username: phone,
                        password: pwd,
                    },
                    dataType: 'JSON',
                    async: false,
                    xhrFields: {
                        withCredentials: true
                    },
                    success: function(data) {

                        if(data.success) {
                            setCookie('token', data.infor[0].token, 365);
                            if(path) {
                                window.location.href = preUrl(path);
                            } else {
                                window.location.href = preUrl('index/index.html');
                            }

                        } else {
                            mask(data.msg);
                        }
                    },
                    error: function(e, request, settings) {
                        alert(settings);
                    }
                })

            })
        });
其他页面当登录令牌过期时跳到登录页面
$.ajax({
                url: reqUrl('year_question'),
                type: 'post',
                dataType: 'json',
                data: {
                    token: token,
                    test_id: pid,
                    id: id
                },
                xhrFields: {
                    withCredentials: true
                },
                success: function(data) {
                    if(data.error_code == 200){
                        window.location.href = preUrl('log/login.html?path=index/all-reapondence.html');
                    }
                    if(data.success) {
                        var respon = template('respon', data);
                        $('.ar-top').html(respon);
                        console.log(data)
                    } else {
                        mask(data.msg);
                    }

                },
                error: function(e, request, settings) {
                    alert(settings);
                }
            });

 

 

 

posted @ 2017-08-15 16:21  欧辰0312  阅读(1889)  评论(0编辑  收藏  举报