0

I have a controller method as below.

public class ProcessorController : System.Web.Http.ApiController
{

    [HttpPost]
    public void Paid(string confirmationNumber)
   {

   }
}

I am trying to call this method from a function in angular js as below. The $http.post is not working. I see an error 'The resource cannot be found' in fiddler when it is trying to hit the path that is specified in $http.post. Can anyone please point out what is going wrong here? Thank you!

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')
                     });
              }
    }
}]);
3
  • Not sure, but shouldn't the url be '/api/processor/paid' ? Commented Apr 6, 2015 at 17:14
  • Thank you. The issue was with url. Commented Apr 6, 2015 at 19:11
  • If only you had asked public void Paid(MyLittleObject obj) where MyLittleObject had a few scalars on it. I'm dying on this one. Commented Jul 27, 2015 at 19:37

1 Answer 1

2

Try it:

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');
                    });
              }
    }
}]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.