Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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
Ajax 我可以怎样做角度跨域post请求?_Ajax_Angularjs_Yii2 - Fatal编程技术网

Ajax 我可以怎样做角度跨域post请求?

Ajax 我可以怎样做角度跨域post请求?,ajax,angularjs,yii2,Ajax,Angularjs,Yii2,我有一个由angular制作的前端。后端由yii2(rest)制作。 我在后端添加了“Access Control Allow Origin:*”标题。 我可以怎样做角度跨域post请求? 如果我执行此代码,我有选项请求,而不是POST: $http .post(API_URL+'auth/login', $scope.credentials) .error(function(error){ Notification.error(error

我有一个由angular制作的前端。后端由yii2(rest)制作。 我在后端添加了“Access Control Allow Origin:*”标题。 我可以怎样做角度跨域post请求? 如果我执行此代码,我有选项请求,而不是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');
        });

使用cors有一些特性。若您使用cookie,则应使用with credentials标志并允许在后端使用此标头。还有一些标题。你可以在这里读到

我不吃饼干。我需要准确地设置angularSo,以便在后端定义允许标头。这对我也很管用。示例:res.header('Access-Control-Allow-Origin','))res.header('Access-Control-Allow-Methods','POST,GET,DELETE,OPTIONS,PUT')res.header('Access-Control-Allow-Credentials','true)res.header('Access-Control-Allow-Headers','Access-Control-Allow-Headers',访问控制允许凭据,访问控制允许方法,内容类型,访问控制允许源')