想将表单json数据发送到其他服务器

时间:2016-02-25 07:29:15

标签: angularjs json angularjs-scope http-post form-submit

我有使用angular在json中输出数据的表单,没有数据库。现在无论该表单的输出是什么,我想将它发送到某个服务器这里是代码说我想将它发送到服务器192.80.36.4例如。如何使用帖子

 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>

1 个答案:

答案 0 :(得分: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);
        })
      }
    };
  }]);