Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS拦截器仅用于GET请求_Javascript_Angularjs_Fullcalendar_Interceptor - Fatal编程技术网

Javascript AngularJS拦截器仅用于GET请求

Javascript AngularJS拦截器仅用于GET请求,javascript,angularjs,fullcalendar,interceptor,Javascript,Angularjs,Fullcalendar,Interceptor,我正试图使用拦截器来拦截我的ajax请求,但是它只适用于GET请求,我使用POST和PUT尝试了它,但注意要做到这一点。有什么想法吗? 下面是我创建拦截器的方法 app.factory('httpInterceptor', ['$q', '$location', '$injector', function ($q, $location, $injector) { return { request: function(config) { var Au

我正试图使用拦截器来拦截我的ajax请求,但是它只适用于
GET
请求,我使用
POST
PUT
尝试了它,但注意要做到这一点。有什么想法吗?
下面是我创建拦截器的方法

app.factory('httpInterceptor', ['$q', '$location', '$injector',
function ($q, $location, $injector) {
    return {
        request: function(config) {
            var AuthService = $injector.get('AuthService');
            console.log(AuthService.getCurrentUser(), AuthService.getCurrentUser().key);
            if(config.usingKey === true) config.headers['X-API-KEY'] = AuthService.getCurrentUser().key;
            if(config.beforeSend && typeof config.beforeSend == "function") config.beforeSend();
            return config;
        }
    };
}]);
我正在用这些服务打电话

angular.module('myapp')
.service('EventService', ['$filter', '$http', 'CONFIG', function ($filter, $http, CONFIG) {
    this.create = function(params, beforeSend, usingkey) {
        if(usingkey == null) usingkey = true;
        return $http.put(CONFIG.DEV ? CONFIG.URL_API_DEV + "event" : CONFIG.URL_API + "event", {params: params, beforeSend: beforeSend, usingKey: usingkey})
    };
}]);
最后,我用这个代码调用我的服务

 select: function (start, end, jsEvent, view, resourceObj) {
    EventService.create({}, function(){
        $('.status').find('i').removeClass("fa-check").addClass("fa-spin fa-circle-o-notch");
    }).then(function($data){
        $('.status').find('i').removeClass("fa-spin fa-circle-o-notch").addClass('fa-check');
        event.realid = $data.data.value.id;
        Calendar.fullCalendar('updateEvent', event);
    }, function(err){
        $('.status').find('i').removeClass("fa-spin fa-circle-o-notch").addClass('fa-close').css({'color': 'red'});
        toastr.error(err);
    });
    $scope.$apply(); // The $apply is for another part of the code, it is required.
 }
如果你有任何想法,请告诉我, 谢谢,祝你今天愉快

  • Nic

出于调试目的,请尝试在$timeout内调用EventService.create。哦,这将是一个好主意。实际上,我会试试。@RafaelP.Miranda它不起作用,不幸的是。显示注册拦截器的代码。@georgeawg这是一个简单的推送
$httpProvider.interceptors.push('httpInterceptor')