可以使用AngularJS的$http.post方法来发送POST请求,并使用表单数据作为参数。示例代码如下:
HTML表单:
JavaScript控制器:
angular.module('app', []) .controller('formController', function($scope, $http) { $scope.submitForm = function() { var data = { name: $scope.name, email: $scope.email }; $http.post('/api/submitForm', data) .success(function(response) { console.log(response); }) .error(function(response) { console.log(response); }); }; });
在控制器中,我们使用$http.post方法向服务器发送POST请求,并将表单数据作为参数传递给该请求。如果请求成功,我们将会在控制台打印响应数据。