0

I'm using angularJS(v1.5.7) in my MVC application. During the development, we used the syntax bellow to make ajax calling::

$http({
  method: 'GET',
  url: "",
  params: { }
}).success(function (data) {
  ...
}).finally(function () {
  ...
});

When I published my application on the server, I'm using bundle to minify my javascript files.

After that, I'm geting the error: ".success is not a function"

Does anybody knows why this issue happen only when I minify the files?

3 Answers3

0

Try using the following syntax

.then(function(success)){  
    ...  
}, function(error){  
    ...  
});

As once answered here for more information. $http.get(...).success is not a function the angular team deprecated success as a function itself in favour of using .then() and passing in first a success function, and a second optional error function passed in.

  • That would be a decision made from the angular team to allow for debugging/troubleshooting deprecated code while upgrading. A lot of rules aren't strictly enforced so your project and functions can still work in debug mode but not once moved into a production environment. It's unfortunate to have to change it in every location, but it's a much easier syntax to read, especially when you can move your success/error call backs seperated in code and just pass the function names in as parameters ex: .then(success, error); function success(response){return true;} etc. – Aaron Bowles Nov 17 '17 at 18:56
0

Syntax looks wrong.

Try below syntax.

    // Simple GET request example:
    $http({
      method: 'GET',
      url: '/someUrl'
    }).then(function successCallback(response) {
       // this callback will be called asynchronously
       // when the response is available
    }, function errorCallback(response) {
       // called asynchronously if an error occurs
       // or server returns response with an error status.
    });
Malatesh Patil
  • 4,505
  • 1
  • 14
  • 14
0

In AngularJS (v1.5.7) there is no any .success event so instead of that in your version use .then for RESTAPI call

$http({
  method: 'GET',
  url: '/Url'
}).then(function successCallback(response) {

  }, function errorCallback(response) { 

  });

For more details you can visit this page https://docs.angularjs.org/api/ng/service/$http

Lakmi
  • 1,379
  • 3
  • 16
  • 27