zoukankan      html  css  js  c++  java
  • 401权限没有放开

    有时,我们的后台接口有权限的限制,不满足权限,就返回错误码401,那么在js中如何判断呢?

    if ((data.status && data.status == '401') || (data.statusText && data.statusText == 'No Transport')) {  
                console.log(data);  
                var currentUrl = window.location.href;  
                window.location.href = currentUrl;  
                return;  
            }  

    下面是真实的返回:

    Object {readyState: 4, responseText: "", status: 401, statusText: "Unauthorized"}

     {readyState: 4, responseText: "", status: 401, statusText: "Unauthorized"}

    java后台代码:

    spring MVC拦截器中的部分代码:

    if(StringUtil.isNullOrEmpty(token)){//added by huangwei  
                            logger.error("token is null");  
                            response.setStatus(401);  
                            return false;  
                        }

     优化如下:

    Js代码
    if ((data.status && data.status == '401') || (data.statusText && (data.statusText == 'No Transport'||data.statusText == 'Unauthorized'))) {  
               console.log(data);  
               var currentUrl = window.location.href;  
               if(currentUrl){  
                   currentUrl=currentUrl.replace(/#$/,'');  
               }  
               window.location.href = currentUrl;  
               return;  
           }  
  • 相关阅读:
    显示多行字符串
    dowhile
    获取系统的相关文件夹
    DLL 实际应用版本
    ShellExecute
    LoadLibrary
    MFC DLL的创建
    在DLL中存放资源
    替换字符串
    RemoveDirectoryB
  • 原文地址:https://www.cnblogs.com/tuziling/p/10497156.html
Copyright © 2011-2022 走看看