Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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 在每个ajax调用中传递公共数据_Javascript_Angularjs - Fatal编程技术网

Javascript 在每个ajax调用中传递公共数据

Javascript 在每个ajax调用中传递公共数据,javascript,angularjs,Javascript,Angularjs,我需要在每个ajax调用中传递rest=1。我该怎么做呢。我可以在全局级别添加它吗,比如转换请求 我的服务就是这样的。我有几个这样的服务,其中只有端点或apipath更改 return $resource(apiPath, { rest: 1, }, { query: { method: 'GET', isArray: true, }

我需要在每个ajax调用中传递rest=1。我该怎么做呢。我可以在全局级别添加它吗,比如转换请求

我的服务就是这样的。我有几个这样的服务,其中只有端点或apipath更改

    return $resource(apiPath, {
        rest: 1,
    }, {
            query: {
                method: 'GET',
                isArray: true,

            }
        }
    );

如果ajaxurl/apiurl不在排除列表中,我只能添加到调用中,这也会很好

请尝试将其添加到主应用程序配置块中

$httpProvider.interceptors.push(function() {
        return {
            'request': function(config) {
                if (config.method === 'POST')
                    angular.extend(config.data, {rest: 1});
                return config;
            }
        };
    });
谷歌是你的朋友:,