首页 新闻 赞助 找找看

angular http有没有jquery ajax 那样的全局事件

0
悬赏园豆:5 [已关闭问题] 关闭于 2015-12-26 12:25

angular http有没有jquery ajax 那样的全局事件

比如请求发送前,请求发送后

天上囧在天上飞的主页 天上囧在天上飞 | 初学一级 | 园豆:6
提问于:2015-12-17 16:16
< >
分享
所有回答(2)
0

是有的。

myModule.factory('myHttpInterceptor', function ($q) {
    return {
        response: function (response) {
            // do something on success
            if(response.headers()['content-type'] === "application/json; charset=utf-8"){
                // Validate response, if not ok reject
                var data = examineJSONResponse(response); // assumes this function is available

                if(!data)
                    return $q.reject(response);
            }
            return response;
        },
        responseError: function (response) {
            // do something on error
            return $q.reject(response);
        }
    };
});
myModule.config(function ($httpProvider) {
    $httpProvider.interceptors.push('myHttpInterceptor');
});
幻天芒 | 园豆:37175 (高人七级) | 2015-12-17 22:45
0

Giant150 | 园豆:1165 (小虾三级) | 2015-12-22 09:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册