【问题标题】:How to trigger function every http request in angularjs如何在angularjs中触发每个http请求的功能
【发布时间】:2019-03-21 01:46:32
【问题描述】:

我只是想知道我们是否可以在每个 http 请求中添加一个函数? 例如。

$http.post('/Customer/FecthCustomer');

我的意思是整个控制器都没有放置每个请求的功能。

我想解决从服务器获取数据后无法获取页面加载事件的问题。 PS(window.setTimeout, window.load, $(document).ready,angular.element(document)) 已测试但无效,它们只会触发页面的每次加载。

【问题讨论】:

  • 尝试使用关键字“angularjs http拦截器”搜索。

标签: javascript jquery angularjs httprequest


【解决方案1】:

感谢@holydragon!

interceptors上搜索。

创建了这个 sn-p:

angular.module('myModule', []).config(function($httpProvider) { 
    $httpProvider.interceptors.push(function($rootScope) {
        return {
            'request': function (config) {
                console.log('REQUEST TRIGGERED');
                return config;
            }
        }
    });
})

【讨论】:

    猜你喜欢
    • 2020-07-23
    • 2021-10-30
    • 1970-01-01
    • 2015-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-20
    • 1970-01-01
    相关资源
    最近更新 更多