我怎么可以做角度跨域发布请求?

时间:2015-11-03 13:58:45

标签: ajax angularjs yii2

我有角度的前端。由yii2(休息)制作的后端。 我在后端添加了“Access-Control-Allow-Origin:*”标题。 我怎么可以做角度跨域发布请求? 如果我执行此代码,我有OPTIONS请求,而不是POST:

$http
        .post(API_URL+'auth/login', $scope.credentials)
        .error(function(error){
            Notification.error(error.message);
            $scope.credentials.sending = false;
        })
        .then(function (res) {
            $cookies.putObject('currentUser', res.data);
            $rootScope.user = res.data;
            $state.go('dashboard');
        });

1 个答案:

答案 0 :(得分:0)

有一些使用cors的功能。如果您使用cookie,则应使用with-credentials标志并在后端允许此标头。还有一些标题。你可以在这里读到它。 http://www.html5rocks.com/en/tutorials/cors/

相关问题