【问题标题】:CORS workaround in Angular.js $HTTP POST?Angular.js $HTTP POST 中的 CORS 解决方法?
【发布时间】:2014-07-24 20:08:14
【问题描述】:

除了使用代理之外,是否有通过 Angular 跨域发送 POST 请求的解决方法?以下请求被拒绝,即: OPTIONS , net::ERR_CONNECTION_REFUSED 这只是我想提交给朋友的本地服务器用于学校项目的表单数据。

$scope.postJSON = function(){
        var objJson = angular.toJson($scope.event);
        console.log(angular.toJson($scope.event));
        delete $http.defaults.headers.common['X-Requested-With'];
        $http({
            method: 'POST',
            url: 'http://friendslocalserver.com',
            data: objJson
        }).success(function() {
            console.log("POST Json object worked!");
        }).error(function(){
            console.log("POST Json object failed!");
        });
    }

【问题讨论】:

    标签: angularjs cors http-post


    【解决方案1】:

    您不需要为 CORS 配置 AngularJS。您朋友的服务器需要支持 CORS 请求,并且可能将您的域列入白名单。这在很大程度上取决于所使用的 HTTP 服务器。

    【讨论】:

      猜你喜欢
      • 2016-06-09
      • 2013-03-20
      • 2016-09-27
      • 2016-05-30
      • 1970-01-01
      • 2017-01-11
      • 2015-06-21
      • 1970-01-01
      • 2020-09-03
      相关资源
      最近更新 更多