使用Google Drive和Angularjs时,不允许使用请求标头字段Accept Encoding



我有一段Angular JS,它读取位于我的Google Drive中的json文件:

yummy.controller("slideCtrl", ['$scope', function($scope) {
}]).directive('slideElement', ['$interval', '$http',($interval, $http) {
return {
    restrict: 'E',
    link: function(scope, element, attrs) {
        var path = 'https://googledrive.com/host/0B-74lO-UfPKoaDRySEsyQkZwNjQ/';
        element.html('<div class="loading"><img src="img/loading.gif"></div>');
        $http({
            method: 'GET',
            url: path + 'reduced.json'
        }).then(function(response) {
            console.log(response.data);
        });
}]);

在Chrome、Firefox以及IE中,代码运行时不会出错。但在Safari中,我得到以下错误:

Failed to load resource: Request header field Accept-Encoding is not allowed by Access-Control-Allow-Headers.

我已经尝试添加:

{ headers: { 'Accept-Encoding': undefined }}

但这并不能解决我的问题。

如何使我的代码在Safari中工作?非常感谢。

我也遇到过类似的问题,但这是因为服务器上的设置错误。

尝试以下代码:

.directive('slideElement', function($http) {
        return {
            restrict: 'E',
            link: function (scope, element, attrs) {
                var path = 'https://googledrive.com/host/0B-74lO-UfPKoaDRySEsyQkZwNjQ/';
                element.html('<div>loading</div>');
                $http({
                    method: 'GET',
                    url: path + 'reduced.json',
                    headers : {
                    'Content-Type' : 'application/json; charset=UTF-8'
                    }
                }).then(function (response) {
                    console.log(response.data);
                }, function(err){console.log("err")});
            }
        }
    })

其中具有内容类型的标头参数是新的。

我希望它能帮助

最新更新