Patrick Reck
Patrick Reck

Reputation: 11374

$http.get with parameters not working

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;
});

Upvotes: 1

Views: 1906

Answers (1)

Madhan Dennis
Madhan Dennis

Reputation: 400

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

Upvotes: 2

Related Questions