2016-02-25 66 views
1

我有形式,在json中使用角度输出数据没有数据库。现在,无论是哪种形式的输出,我都希望将它发送给某个服务器。下面是代码,例如我想将它发送到服务器192.80.36.4。如何做到这一点使用后想要发送表单json数据到其他服务器

controller definition code 


<body ng-app="submitExample"> 
    <script> 
    angular.module('submitExample', []) 
    .controller('ExampleController', ['$scope', function($scope) { 
    $scope.list = []; 
    $scope.text = ''; 
    $scope.submit = function() { 
    if ($scope.text) { 
     $scope.list.push(this.text); 
     $scope.text = ''; 
    } 
    }; 
    }]); 
    </script> 

    </script> 
    <form ng-submit="submit()" ng-controller="ExampleController"> 
     Enter latitude: 
     <input type="text" ng-model="text" name="text" /> 
     <input type="submit" id="submit" value="Submit" /> 
     <pre>list={{list| json}}</pre> 
    </form> 

回答

3

您需要使用$http服务:

angular.module('submitExample', []) 
    .controller('ExampleController', ['$scope', '$http', function($scope, $http) { 
    $scope.list = []; 
    $scope.text = ''; 
    $scope.submit = function() { 
     if ($scope.text) { 
     $scope.list.push(this.text); 
     $scope.text = ''; 
     $http.post("<your-url>", $scope.list).success(function(data, status) { 
      console.log(data); 
     }) 
     } 
    }; 
    }]); 
+0

,我想将数据发送到服务器的网址是什么? – koku19

+0

我不知道你在哪里发送你的数据。您需要一台能够捕获您的POST请求的服务器。 –

+0

XMLHttpRequest无法加载http://183.000.00.00/t/db/。对预检请求的响应不会通过访问控制检查:请求的资源上不存在“访问控制 - 允许来源”标头。 Origin'example.com'因此不被允许访问。 这是错误 – koku19

相关问题