1

I am trying to send a GET request using AnguarJS $http.get function.

However, the shorthand version is NOT working. Why is that?

Working:

$http({
    url: $rootScope.root + '/brands',
    method: 'GET',
    params: postData
}).success(function(data) {
    console.log(data);
});

Not working:

$http.get($rootScope.root + '/brands', postData).success(function(data) {
    console.log(data);
    $scope.brands = data;
});
Patrick Reck
  • 11,246
  • 11
  • 53
  • 86

1 Answers1

2

The 2nd parameter for the $http.get shortcut method is meant to pass in parameters such as cache control, etc. Only for $http.post does the 2nd parameter accept the post data. If you are using the shortcut for $http.get you will need to pass in the query parameters as part of the URL: $http.get($rootScope.root + '/brands?a=1&b=2')

Ref: http://docs.angularjs.org/api/ng.$http#methods_get

Madhan Dennis
  • 400
  • 1
  • 4