ajax处理session过期

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="lib/jquery-3.4.1.min.js"></script>
<script type="text/javascript">

        $.ajaxPrefilter(function(options,originalOptions,jqXHR){
                
                //pre callback process
                var originSuccess = options.success;
                if(originSuccess === undefined){
                    originSuccess = function(){
                        
                    };
                }
            
                options.success = function(data,textStatus,jqXHR){
                    var errorcode = data.errorcode;
                    if(errorcode == -1){
                        alert("Session过期了");
                        
                    }
                    else{
                        originSuccess.apply(this,[data,textStatus,jqXHR]);
                    }
                }
        })

        function testAjax(){
                $.ajax({
                        url:'Test/Test',
                        async:false,
                        data:{},
                        success:function(response){
                                alert(response.errorcode);
                                alert(response.mess);
                        },
                        error:function(){
                            
                        }
                });
        }
</script>
</head>
<body>
<input type="button" value="testAjax" id="testAjax" οnclick="testAjax()"/>
</body>
</html>

发布了8 篇原创文章 · 获赞 0 · 访问量 427

猜你喜欢

转载自blog.csdn.net/xiaokanfuchen86/article/details/103878632