zoukankan      html  css  js  c++  java
  • Angularjs中config中置入以下拦截器

    $httpProvider.interceptors.push(['$rootScope', '$q', '$localStorage', function ($rootScope, $q, $localStorage) {
          return {
            request: function (config) {
    
              // Header - Token
              config.headers = config.headers || {};
              if ($localStorage.token) {
                config.headers.token = $localStorage.token;
              };
              
              return config;
            },
    
            response: function (response) {
    
              if (response.status == 200) {
                // console.log('do something...');
              }
              
              return response || $q.when(response);
            },
    
            responseError: function (response) {
            
              return $q.reject(response);
            }
          }
        }])

    基于这样的问题:

    想使用angularjs里的htpp向后台发送请求,后台是基于tornado的,现在有个用户唯一识别的token想要放到headers里面去,也就是{headres:{'token':1}},但是尝试了很多方法不行,想问下应该怎么做,后台需不需要设置一些什么东西,多谢

    上面是参考解决方法之一

  • 相关阅读:
    hw4 打卡
    lab4打卡
    hw3打卡
    lab3打卡
    hw2打卡
    lab2打卡
    hw1打卡
    Java Trie(词典树)实现
    Java HashMap实现
    DFS习题复习(2) DFS的实际应用:括号检测,graph Bipartite及随机生成迷宫
  • 原文地址:https://www.cnblogs.com/hubing/p/6020107.html
Copyright © 2011-2022 走看看