angularjs cors请求:拒绝访问受限制的URI(仅限Firefox)

时间:2016-01-29 18:08:02

标签: javascript angularjs ajax gulp cors

我有一个带有gulp的angularjs(1.4.7)前端,需要向Django RESTful API发出cors请求。 后端服务器设置为允许cors请求并登录在Chrome中正常工作。虽然在Firefox(第44节)中我无法登录。我在控制台中看到了这一点:

Error: Access to restricted URI denied
createHttpBackend/<@http://localhost:3000/bower_components/angular/angular.js:10765:1

整个追溯在这里:http://pastebin.com/GfdK6LJ9

更改security.fileuri.strict_origin_policy参数无效。 根据firebugs XHR标签,浏览器首先发送POST请求。

以下是登录代码:

angular.module('myapp')
    .controller(
        'AuthController', ['$rootScope', '$scope', '$location', '$timeout', 'AuthService', 
        function ($rootScope, $scope, $location, $timeout, AuthService) {
            $scope.loginData = {};
            $scope.loginErrorMsg = '';
            $scope.currentUser = AuthService.getUser();

            $scope.LoginSubmit = function() {
                $scope.loginErrorMsg = '';

                if( !$scope.loginData.username && !$scope.loginData.password ) {
                    return;
                }

                AuthService.login({
                    username: $scope.loginData.username,
                    password: $scope.loginData.password
                })
                .then(function(data) {
                    $timeout(function(){
                        $location.url('/');
                    }, 1000)
                }, function(error){
                    $scope.loginErrorMsg = error.non_field_errors[0];
                });

                return false;
            };

            $scope.logout = function () {
                AuthService.logout();
                $location.url('/login');
            };

        }])
;

任何建议表示赞赏:)

更新

以下是Chrome中发生的情况: 它发送一个OPTION请求,得到200个响应,然后发送一个POST请求。

http://pastebin.com/rARdwVHK

我现在注意到,在我的localhost开发中,登录适用于两种浏览器,尽管存在差异。在Django的日志中,我可以看到Chrome为每个API调用发送OPTION请求,但Firefox不发送任何OPTION请求。

我认为这与此问题类似:

Firefox won't send Cross-Origin Resource Sharing Pre-flight?

0 个答案:

没有答案
相关问题