AngularJs $ http动作钩子之前的帖子 [英] AngularJs $http post before action hook

查看:71
本文介绍了AngularJs $ http动作钩子之前的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的$ http电话. angular是否具有某些功能,例如成功之前,该功能将在实际的$ http调用之前执行

Below is my $http call . Does angular has some function like success say before which will execute before actual $http call

 $http.post(postUrl, $scope.tempData, {
        }).success(function(response) {

                alert(response); 

       }).error(function (errorCode) {

           alert(errorCode); 
       }
           );

推荐答案

angular是否具有某些功能,例如成功说,它将在实际的$ http调用之前执行.

Does angular has some function like success say before which will execute before actual $http call.

快速解答:否

但是您可以在factoryprovider中实现此模块,并实现所需的任何逻辑.

But you can implement this module in factory or provider and implement any logic you want.

以下是示例:

.factory('ajax_post', ['$http', function(_http) {

    var path = 'src/php/data.ajax.php';

    return{
        init: function(jsonData){

            // do logic here


            var _promise= _http.post(path, 
                jsonData
                ,{
                    headers: {
                        'SOAPActions': 'http://schemas.microsoft.com/sharepoint/soap/UpdateListItems'
                    }
                }
                );            
            return _promise; 
        }

    }   
}]);

这篇关于AngularJs $ http动作钩子之前的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆