如何使用 angular js $http post 调用控制器 [HttpPost] 方法?
How to call controller [HttpPost] method using angular js $http post?
我有一个控制器方法如下。
public class ProcessorController : System.Web.Http.ApiController
{
[HttpPost]
public void Paid(string confirmationNumber)
{
}
}
我正在尝试从 angular js 中的函数调用此方法,如下所示。 $http.post 不工作。当 fiddler 试图访问 $http.post 中指定的路径时,我在 fiddler 中看到一个错误 'The resource cannot be found'。谁能指出这里出了什么问题?谢谢!
var payControllers = angular.module('payControllers', []);
payControllers.controller('payCtrl', ['$scope', '$http',
function ($scope, $http) {
$scope.Process = function(confnumber) {
$scope.ConfNumber = confnumber;
if ($scope.ConfNumber.length > 0) {
$http.post('/Processor/Paid',
{
confirmationNumber: $scope.ConfNumber
}
).success(function () {
alert('updated')
});
}
}
}]);
试一试:
var payControllers = angular.module('payControllers', []);
payControllers.controller('payCtrl', ['$scope', '$http',
function ($scope, $http) {
$scope.Process = function(confnumber) {
$scope.ConfNumber = confnumber;
if ($scope.ConfNumber.length > 0) {
$http({
url: '/api/Processor/Paid?confirmationNumber='+$scope.ConfNumber,
method: 'POST'
}).success(function (data) {
alert('updated');
});
}
}
}]);
我有一个控制器方法如下。
public class ProcessorController : System.Web.Http.ApiController
{
[HttpPost]
public void Paid(string confirmationNumber)
{
}
}
我正在尝试从 angular js 中的函数调用此方法,如下所示。 $http.post 不工作。当 fiddler 试图访问 $http.post 中指定的路径时,我在 fiddler 中看到一个错误 'The resource cannot be found'。谁能指出这里出了什么问题?谢谢!
var payControllers = angular.module('payControllers', []);
payControllers.controller('payCtrl', ['$scope', '$http',
function ($scope, $http) {
$scope.Process = function(confnumber) {
$scope.ConfNumber = confnumber;
if ($scope.ConfNumber.length > 0) {
$http.post('/Processor/Paid',
{
confirmationNumber: $scope.ConfNumber
}
).success(function () {
alert('updated')
});
}
}
}]);
试一试:
var payControllers = angular.module('payControllers', []);
payControllers.controller('payCtrl', ['$scope', '$http',
function ($scope, $http) {
$scope.Process = function(confnumber) {
$scope.ConfNumber = confnumber;
if ($scope.ConfNumber.length > 0) {
$http({
url: '/api/Processor/Paid?confirmationNumber='+$scope.ConfNumber,
method: 'POST'
}).success(function (data) {
alert('updated');
});
}
}
}]);